JS实现点击复选框后文本框变可编辑 请教个问题,js如何实现当复选框选中状态时后面的文本框可编辑,当没选中时文本框文本框的值为空 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.2.6.min.js"></script></head><body><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><script type="text/javascript">window.onload = function(){ var ipts = document.getElementsByTagName("input"); for(var i=0;i<ipts.length;i++) { if(ipts[i].type=="text") { ipts[i].disabled = true; } else { ipts[i].onclick=function() { if(this.checked) this.nextSibling.disabled = false; else this.nextSibling.disabled = true; } } }}</script></body></html> 初学啊,问个幼稚的问题啊,this.nextSibling.disabled = false;中,nextSibling指的是下一个输入框??? nextSibling 属性可返回某个元素之后紧跟的元素(处于同一树层级中)。如果无此节点,则属性返回 null。http://www.w3school.com.cn/xmldom/prop_node_nextsibling.asp <!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/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.2.6.min.js"></script></head><body><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><input type="checkbox" /><input type="text" /><br/><script type="text/javascript">window.onload = function(){ var ipts = document.getElementsByTagName("input"); for(var i=0;i<ipts.length;i++) { if(ipts[i].type=="text") { ipts[i].disabled = true; } else { ipts[i].onclick=function() { if(this.checked) this.nextSibling.disabled = false; else this.nextSibling.disabled = true; } } }}</script></body></html> 好东西,学习,收藏博客了:http://www.itgoto.com.cn/?action=show&id=191 <input type="checkbox" onclick="this.nextSibling.disabled=!this.nextSibling.disabled" /><input disabled/> <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title> <script type="text/javascript"> function setText(obj) { if(obj.checked==true) { document.getElementById("txtName").disabled=false; } else { document.getElementById("txtName").disabled=true; document.getElementById("txtName").value=""; } } </script></head><body> <form id="form1" runat="server"> <div> <input id="Checkbox1" type="checkbox" onclick="setText(this)" /> <input id="txtName" type="text" /> </div> </form></body></html> 12楼的 一开始onclick没触发,text是可编辑的,有点小问题,呵呵 一开始 disabled="false" 就好了 12楼的也不对,要是考虑刷新加个onload函数即可了。 实用的东西,学习了,虽然Jquery方便,但还是知道基本原理之后再用的好。 JS弹出回复留言框的问题 关闭页面时,让其收藏的功能,在线等 Javascript中继承的问题 JS提取字符 如何用javascript检测CPU和内存信息? JS如何播放.wav文件 求一個連接方法 帮忙解决日期判断的问题?谢谢! 为何通过Form引用控件时有的属性就不能用了 如何强迫下载文本? 求助jquey异步返回值问题 求肋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/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
</head>
<body>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<script type="text/javascript">
window.onload = function()
{
var ipts = document.getElementsByTagName("input");
for(var i=0;i<ipts.length;i++)
{
if(ipts[i].type=="text")
{
ipts[i].disabled = true;
}
else
{
ipts[i].onclick=function()
{
if(this.checked)
this.nextSibling.disabled = false;
else
this.nextSibling.disabled = true;
}
}
}
}
</script>
</body>
</html>
中,nextSibling指的是下一个输入框???
如果无此节点,则属性返回 null。http://www.w3school.com.cn/xmldom/prop_node_nextsibling.asp
<!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/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
</head>
<body>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<input type="checkbox" /><input type="text" /><br/>
<script type="text/javascript">
window.onload = function()
{
var ipts = document.getElementsByTagName("input");
for(var i=0;i<ipts.length;i++)
{
if(ipts[i].type=="text")
{
ipts[i].disabled = true;
}
else
{
ipts[i].onclick=function()
{
if(this.checked)
this.nextSibling.disabled = false;
else
this.nextSibling.disabled = true;
}
}
}
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function setText(obj)
{
if(obj.checked==true)
{
document.getElementById("txtName").disabled=false;
}
else
{
document.getElementById("txtName").disabled=true;
document.getElementById("txtName").value="";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Checkbox1" type="checkbox" onclick="setText(this)" />
<input id="txtName" type="text" />
</div>
</form>
</body>
</html>