1:使用javascript实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<select name="jumpMenu" id="jumpMenu" onChange="jumpMenu('parent',this,0)">
<option id="1" value="跳转URL">111</option>// 111 是显示给用户的信息
<option id="2" value="跳转URL">222</option>
<option id="3" value="跳转URL">333</option>
<option id="4" value="跳转URL">444</option>
<option id="5" value="跳转URL">555</option>
</select>
<script type="text/javascript">
function display(optionID){
var all_options = document.getElementById("jumpMenu").options
for (i=0i<all_options.lengthi++){
if (all_options[i].id == optionID) // 根据option标签的ID来进行判断 测试的代码这里是两个等号
{
all_options[i].selected = true
}
}
}
display("4")
</script>
</body>
</html>
2:使用jQuery实现
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<select name="jumpMenu" id="jumpMenu" >
<option value="1">111</option>// 111 是显示给用户的信息
<option value="2">222</option>
<option value="3">333</option>
<option value="4">444</option>
<option value="5">555</option>
</select>
<script type="text/javascript" src="js/jquery1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
// $("#jumpMenu").val(要选中的option的value值即可)
$("#jumpMenu").val(4)
})
</script>
</body>
</html>
很简单通过document.getELementById("你的select标签id").value=你数据库的值即可
有疑问可以call
我
本人q
345032463
获取select标签,设置它的value值和option的value值相同<select name="" id="test" value="one">
<option value="one">one</option>
<option value="two">two</option>
</select>
<button id="btn">改变选中状态</button>
<script type="text/javascript">
var select = document.querySelector('#test')
var btn = document.querySelector('#btn')
btn.onclick = function () {
if (select.value === 'one') {
select.value = 'two'
} else {
select.value = 'one'
}
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)