Home > Article > Web Front-end > How to set default value for bootstrap drop-down list
Get the value from the drop-down box and set the default value:
##
<select id="test"> <option value="1">选项一<option> <option value="2">选项一<option> ... <option value="n">选项N<option> </select>The so-called jQuery operation "select", To be more precise, jQuery should control "option". Look at the jQuery code below: //Get the value of the first option
$('#test option:first').val();//The value of the last option
$('#test option:last').val();//Get the value of the second option
$('#test option:eq(1)').val();//Get the selected value
$('#test').val(); $('#test option:selected').val();//Set the option with a value of 2 to the selected state
$(‘#test’).attr(‘value’,’2’);//Set the last option to be selected
$('#test option:last').attr('selected','selected'); $("#test").attr('value' , $('#test option:last').val()); $("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());//Get the length of the select
$('#test option').length;//Add an option
$("#test").append("<option value='n+1'>第N+1项</option>"); $("<option value='n+1'>第N+1项</option>").appendTo("#test");//Add and remove Selected item
$('#test option:selected').remove();//Delete the selected item (the first item is deleted here)
$('#test option:first').remove();、//The specified value is deleted
$('#test option').each(function(){ if( $(this).val() == '5'){ $(this).remove(); } }); $('#test option[value=5]').remove();//Get the label of the first Group
$('#test optgroup:eq(0)').attr('label');//Get the value of the first option under the second group
$('#test optgroup:eq(1) : option:eq(0)').val();//select is selected by default
$("#arrangeClass").find("option[value="+reim.classId+"]").prop("selected",true);Recommended:
bootstrap introductory tutorial
The above is the detailed content of How to set default value for bootstrap drop-down list. For more information, please follow other related articles on the PHP Chinese website!