两个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");
找不到对象,菜鸟求指导
解决方案 »
- 高分求JS实现SVG多个对像一起拖动的代码修改
- document.body.appendChild()导致IE已终止操作的讨论
- 子页面操作父页面里的标签
- 简单投票系统
- javascript带参数问题!!急急!
- 框架左侧-菜单页的隐、显-图钉固定-期盼雪花大侠代码已有盼...
- 高手请进,菜鸟送分,在线等候,立刻结帖.
- 如何设置窗口在30秒无鼠标或键盘响应的情况下自动关闭?
- 请问有没有方法使用程序,控制调整框架中各页面的大小?
- jstree读取到后台数据json字符串后,怎么显示到前台?
- 正则表达式求 求详解求详解]
- 神马的加密 求高手解密_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);
}
}