两个select下拉框 实现根据s1的下拉选项控制s2可不可选
如下代码:
html:
<td><select id='s1' onchange='s1OnChange(this);'><option>可选</option><option>不可选</option></select></td>
<td><select id='s2'><option>No</option><option>Yes</option></select></td>js:
function s1OnChange(itemObj) {
var selectIndex = itemObj.getAttribute("selectedIndex");
if (selectIndex == 0) //可选
{
document.getElementById("s2").setAttribute("disabled", "true");
}
else
{
document.getElementById("s2").setAttribute("disabled", "false");
}
}
运行调试看到:selectIndex 取到的是null,document.getElementById("s2").setAttribute("disabled", "false");
找不到对象,菜鸟求指导
如下代码:
html:
<td><select id='s1' onchange='s1OnChange(this);'><option>可选</option><option>不可选</option></select></td>
<td><select id='s2'><option>No</option><option>Yes</option></select></td>js:
function s1OnChange(itemObj) {
var selectIndex = itemObj.getAttribute("selectedIndex");
if (selectIndex == 0) //可选
{
document.getElementById("s2").setAttribute("disabled", "true");
}
else
{
document.getElementById("s2").setAttribute("disabled", "false");
}
}
运行调试看到:selectIndex 取到的是null,document.getElementById("s2").setAttribute("disabled", "false");
找不到对象,菜鸟求指导
解决方案 »
- 使用jQuery的$.get方法远程请求返回值问题。现在不能返回。
- 网页里表格的信息数据从下方负担上来 到表格位置停止 用JS代码如何实现 急求~~~~
- 怎样在父页面中控制子页面失焦和得焦
- 求救 ,一个JS问题烦了我几天了,大侠们在哪呀
- 问个frame的问题!
- 如何更改html页面的默认脚本语言
- showModelessDialog打开的窗口如何通过cloneNode复制父窗口的一个表格对象?
- 急:还是关于动态在表格中插入一行的问题。
- 请问那位知道好的网页素材的网站
- js变量赋值
- 正则表达式求 求详解求详解]
- 神马的加密 求高手解密_64值 function+_lOlOl100 play.html 帖子2
<head>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript">
function s1OnChange(itemObj) {
var selectIndex = itemObj.getAttribute("selectedIndex");
if (selectIndex == 0) //可选
{
document.getElementById("s2").setAttribute("disabled", false);
}
else
{
document.getElementById("s2").setAttribute("disabled", true);
}
}</script>
</head>
<body>
<td><select id='s1' onchange='s1OnChange(this);'><option>可选</option><option>不可选</option></select></td>
<td><select id='s2'><option>No</option><option>Yes</option></select></td>
</body>
</html>
改成这样<script type="text/javascript" src="a.js?1"></script>测试一下 原来的方法 火狐下有问题
改成这样 应高没问题了
function s1OnChange() {
var selectIndex = document.getElementById("s1").value;
alert(selectIndex=="0");
if (selectIndex == "0") //可选
{
document.getElementById("s2").removeAttribute("disabled");
}
else
{
document.getElementById("s2").setAttribute("disabled",true);
}
}