var value="南京";
$("select").children("option").each(function(){
var temp_value = $(this).val();
// var temp_value = $(this).text();
if(temp_value == value){
$(this).attr("selected","selected");
}
});
本文介绍了一段使用JavaScript操作HTML中select元素的代码,该代码能够根据预设值自动为下拉选项设置默认选中项,适用于网页开发中初始化表单的需求。
var value="南京";
$("select").children("option").each(function(){
var temp_value = $(this).val();
// var temp_value = $(this).text();
if(temp_value == value){
$(this).attr("selected","selected");
}
});

被折叠的 条评论
为什么被折叠?
