<select id="command_option" name="command[option]">
<option value="">...Select a command...</option>
<option value="action">Action</option>
<option value="update_timer">Update Timer</option>
<option value="gather_timer">Gather Timer</option> </select>我想做的工作是当页面加载的时候,select 的的二个元素有个CLICK事件选中这个元素,也就是代替我了我手动的CLICK事件.求解!
用jquery操作!
<option value="">...Select a command...</option>
<option value="action">Action</option>
<option value="update_timer">Update Timer</option>
<option value="gather_timer">Gather Timer</option> </select>我想做的工作是当页面加载的时候,select 的的二个元素有个CLICK事件选中这个元素,也就是代替我了我手动的CLICK事件.求解!
用jquery操作!
if(myoptions.length>1){
myoptions[1].selected=true;
}
var i = 1; // 第二个
var $command = $("#command_option")
var $options = $("#command_option option");
$command.val($options.eq(i).val())
}
function selectYou(i){
$("#command_option").val(function(){
return $(this).find("option").eq(i-1).val()
})
}这样就可以直接调用selectYou(i)函数了,i表示第几个
$("#command_option").val("你要选中的option的值")
<!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>
<title></title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.4.4.js"></script>
<script type="text/javascript">
//在页面加载完毕之后
$(function() {
//select的选中值设置为它第二个option的值
$("#command_option").val($("#command_option option:eq(1)").val());
});
</script>
</head>
<body>
<form action="" method="post" >
<div>
<select id="command_option" name="command[option]">
<option value="">...Select a command...</option>
<option value="action">Action</option>
<option value="update_timer">Update Timer</option>
<option value="gather_timer">Gather Timer</option>
</select>
</div>
</form>
</body>
</html>
//在页面加载完毕之后
$(function() {
//select的选中值设置为它第二个option的值
$("#command_option").val($("#command_option option:eq(1)").val());
$("#command_option").change();
});