RadioButton input CheckBox value assignment in jQuery implementation code
- 2021-01-14 05:44:52
- OfStack
1, jquery Get the radio group radio
$("input[name='name']:checked").val();
2, jquery Gets the next value of radiobutton
$("input[name='name']:checked").next().text()
$("input[name='name']:checked").val()
jquery = input = input
$('#id').val()
4, jquery judge multi-check checkbox
$("#id:checkbox").attr("checked")
Value $(" # id "). attr (" value ");
Assignments are given directly in text() and val()
JQUERY how to obtain text areatext, radio, checkbox, select value?
$("input").val();
$("textarea").text();
$("select").val();
Control form elements:
$("#txt").attr ("value", ""); // Clear the content
$("#txt").attr("value",'11'); // Fill in the content
checkbox: $("#chk1").attr("checked", "); / / no box
$("#chk2").attr("checked",true); / / box
if($("#chk1").attr('checked')==undefined) // Check if the box is checked
Radio set radio: $(" input [@ type = radio] "). The attr (" checked ", '2'); // Set the item with value=2 as the currently selected item
Drop-down box select: $(" # sel "). attr (" value, "' - sel3 '); // Set the item value= -sel3 as the currently selected item
$("
<
option value='1'
>
1111
<
/option
>
<
option value='2'
>
2222
<
/option
>
").appendTo("#sel")// Add the drop-down box to option
$(" # sel "). empty (); // Clear the drop-down box
jQuery Gets and sets the values of the select drop-down box
Get Select:
SELECT text FROM select SELECT text FROM select
$("#ddlRegType").find("option:selected").text();
Select value from select:
$("#ddlRegType ").val();
To get the index selected by select:
$("#ddlRegType ").get(0).selectedIndex;
Set select:
Set the index selected by select:
$("#ddlRegType ").get(0).selectedIndex=index; //index is the index value
Set value to select:
$(" # ddlRegType "). attr (" value Normal ", "");
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
Set select to text:
var count=$("#ddlRegType option").length;
for(var i=0;i
<
count;i++)
{ if($("#ddlRegType ").get(0).options[i].text == text)
{
$("#ddlRegType ").get(0).options[i].selected = true;
break;
}
}
$("#select_id option[text='jQuery']").attr("selected", true);
select Set option item:
$("#select_id").append("
<
option value='Value'
>
Text
<
/option
>
"); // Add an option entry
$("#select_id").prepend("
<
option value='0'
>
Please select a
<
/option
>
"); // Insert option in front of you
$("#select_id option:last").remove(); // Delete Option with the largest index
$("#select_id option[index='0']").remove(); // Delete Option with index 0
$("#select_id option[value='3']").remove(); // Delete Option with value 3
$("#select_id option[text='4']").remove(); // Delete Option where TEXT value is 4
Empty Select:
$("#ddlRegType ").empty();