简单的问题,你不一定解决的掉,O(∩_∩)O哈哈~

dy360mpt7eucig 2010-01-18 09:11:07
在JS里面控制文本框的启用与停用时,总是会调用文本框里的事件,有没有什么方法可以让他不要调用文本框里的事件呀?
...全文
92 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
dy360mpt7eucig 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yixianggao 的回复:]
L@_@K

HTML code<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title> new document</title><metaname="generator" content="editplus"/><metaname="author" content=""/><metaname="keywords" content=""/><metaname="description" content=""/></head><body><inputtype="text" id="txtTest" value="文本框"/><inputtype="button" id="btnSwitch" value="Switch"/><scripttype="text/javascript"><!--var $= document.getElementById;var DISABLED_TEXT="禁用";var btn= $("btnSwitch");
btn.value= DISABLED_TEXT;var txt= $("txtTest");

btn.onclick=function() {
txt.disabled= (btn.value== DISABLED_TEXT);
btn.value= txt.disabled?"启用" : DISABLED_TEXT;
};//--></script></body></html>
[/Quote]
大哥,文本框的启用或禁用是一个属性Enabled,不是文本。+_+
dy360mpt7eucig 2010-01-18
  • 打赏
  • 举报
回复
算了,你们就告诉我,如何使用JS控制id="add"文本框的事件的启用或禁用??????
浴火_凤凰 2010-01-18
  • 打赏
  • 举报
回复
真的是不能解决啊!没有明白什么意思。
h155290688 2010-01-18
  • 打赏
  • 举报
回复
具体做法应该是在需要用事件的时候就添加事件,用完之后就删除掉,除非这个事件一直被触发,所以要动态绑定事件
kuiyouli 2010-01-18
  • 打赏
  • 举报
回复
event.cancelBubble=true
event.returnValue=false

这样应该可以阻止事件冒泡



面向对象的CSS:OOCSS
http://www.oocss.cc
kuiyouli 2010-01-18
  • 打赏
  • 举报
回复
event.cancelBubble=true




面向对象的CSS:OOCSS
http://www.oocss.cc
antony1029 2010-01-18
  • 打赏
  • 举报
回复
那只能把事件移除啊。
yixianggao 2010-01-18
  • 打赏
  • 举报
回复
L@_@K

<!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> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<input type="text" id="txtTest" value="文本框" /><input type="button" id="btnSwitch" value="Switch" />
<script type="text/javascript">
<!--
var $ = document.getElementById;

var DISABLED_TEXT = "禁用";
var btn = $("btnSwitch");
btn.value = DISABLED_TEXT;

var txt = $("txtTest");

btn.onclick = function() {
txt.disabled = (btn.value == DISABLED_TEXT);
btn.value = txt.disabled ? "启用" : DISABLED_TEXT;
};
//-->
</script>
</body>
</html>
duwa789 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dy360mpt7eucig 的回复:]
如果文本框里还有第2个事件,那么在你设置aa.disabled = true时,就会调用第2个事件,怎么才能让它不调用第2个事件呢?
[/Quote]

没看懂…… 举个例子?
dy360mpt7eucig 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhangshaolongjj 的回复:]
<input type="text" value="000110" onclick="a(this)" />
<script type="text/javascript">
function a(aa){
  aa.disabled = true;
}
</script>
[/Quote]
如果文本框里还有第2个事件,那么在你设置aa.disabled = true时,就会调用第2个事件,怎么才能让它不调用第2个事件呢?
zhangshaolongjj 2010-01-18
  • 打赏
  • 举报
回复
<input type="text" value="000110" onclick="a(this)" />
<script type="text/javascript">
function a(aa){
aa.disabled = true;
}
</script>
nyeah 2010-01-18
  • 打赏
  • 举报
回复
总是会调用文本框里的事件?什么事件?

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧