- HTML code
<select class="select" name="outlet_first" id="outlet_first" valid="required" errmsg="请选择所属公司!"> <option label="暂无" value="1">暂无</option> <option label="鸿佳不动产" value="44" selected="selected">鸿佳不动产</option> <option label="爱家房屋" value="45">爱家房屋</option> <option label="西海岸房产网" value="46">西海岸房产网</option> <option label="太平洋房屋" value="47">太平洋房屋</option> <option label="千翔房产店" value="48">千翔房产店</option> <option label="青岛鼎铭不动产有限公司" value="49">青岛鼎铭不动产有限公司</option> <option label="青岛祺瑞房产投资有限公司" value="56">青岛祺瑞房产投资有限公司</option> </select>
- JScript code
<script language="javascript"> $("#outlet_last").change(function(){ alert(document.getElementById("outlet_last").value); //$onedef=load("../zhongjie/login_oneList_ajax.php?id="+$("#outlet_last").val()); document.getElementByName("outlet_first").options[46].selected=true; }); </script>
document.getElementByName("outlet_first").options[46].selected=true;
这一句报错 SCRIPT5007: 无法设置属性“selected”的值: 对象为 null 或未定义
麻烦高手们帮看看,感谢
------解决方案--------------------
既然已经使用了jQuery,干嘛不使用jQuery的方法来设置呢:
- JScript code
$("#outlet_first").val(46);
------解决方案--------------------
不使用jQuery:
- JScript code
document.getElementsByName('outlet_first')[0].value = 46; //或者 document.getElementsByName('outlet_first')[0].getElementsByTagName('option')[3].selected = true;
------解决方案--------------------
你有id.为何不用id来检索呢?
document.getElementById("outlet_first").options[3].selected=true; //选项索引不能用value值,从0开始,1...