I want a checkbox to be checked by default,
This question already has an answer here:
请试试这个
<select name="semester">
<option value="">Select Semester</option>
<option value="1" <?php if($data['semester']==1){echo 'selected';}?>>Semester 1</option>
<option value="2" <?php if($data['semester']==2){echo 'selected';}?>>Semester 2</option>
<option value="3" <?php if($data['semester']==3){echo 'selected';}?>>Semester 3</option>
</select>
您可以使用selected
属性。
<select name="semester">
<option value="">Select Semester</option>
<option value="1" selected="selected">Semester 1</option>
<option value="2">Semester 2</option>
<option value="3">Semester 3</option>
</select>
If you want to select semester 2
so here you go:
HTML:
<select name="semester">
<option value="">Select Semester</option>
<option value="1">Semester 1</option>
<option value="2" selected>Semester 2</option>
<option value="3">Semester 3</option>
</select>
Jquery:
$("select option").each(function(){
if ($(this).text() == "Semester 2")
$(this).attr("selected","selected");
});
链接地址: http://www.djcxy.com/p/88074.html
上一篇: <select>默认值
下一篇: 我想要一个复选框被默认选中,