javascript jquery Details of Common Operations for form Elements
- 2021-06-28 10:16:31
- OfStack
1. Dropdown box select:
Remove option
$("#ID option").each(function(){
* if($(this).val() == 111){
* $(this).remove();
}
});
Add option
$("<option value='111'>UPS Ground</option>").appendTo($("#ID"));
Gets the selected value of the drop-down menu
// Remove text from a drop-down
$('#testSelect option:selected').text();
$("#testSelect").find('option:selected').text();
document.all.objSelect.options[document.all.objSelect.selectedIndex].text; //js operation objSelect � select Of name// Get Dropdown Median
$("#testSelect").val();
//js operation
document.getElementById('objSelect').value=2;
document.all.objSelect.value;
Select the drop-down box based on the value of option
$('#testSelect').val('111');document.all.objSelect.value = objItemValue; //js operation objSelect � select Of name perhaps iddocument.getElementById('sel').value=objItemValue;
The second element of the select drop-down box is the current selected value
$('#select_id')[0].selectedIndex = 1;
2, check box radio:
$("input[type=radio][checked]").val(); // Get the value of the selected item of the radio box ( Notice that there is no space in the middle )
$(':radio[name="radio"]:checked').val();// No. 2 Method
$("input[type=radio][value=2]").attr("checked",'checked'); // Set Radio Box value=2 Is selected .( Notice that there is no space in the middle )
$(':radio[value="2"]').attr('checked','checked');
The second element of the radio radio group is the current selected value
$("input[name='items']").get(1).checked = true;
3, check box checkbox: (see above: radio for additional writing)
$("input[type='checkbox'][checked]").val(); // Get the checked number of 1 Value of item
$("#chk1").attr("checked",'');// Uncheck
$("#chk2").attr("checked",true);// tick
// Holistic / No
$("#selectAll").bind('click',function(){
var sa = $(this).attr("checked");
$("input[name='sel[]']").each(function(){
this.checked=sa;
});
});
4, ** box input:
$(':input[name="keyword"]').val();// according to name Value Get Value
5, Textbox textarea:
Fixed text box size:
<textarea name="123" style="resize:none;"></textarea>