+ -
当前位置:首页 → 问答吧 → 新手求助一个给input绑定事件的代码

新手求助一个给input绑定事件的代码

时间:2010-06-06

来源:互联网

RT,下面的代码运行不了,郁闷。。。。
<html> <head> <script> var $=function(ids){ return document.getElementById(ids); } $("ssn").onclick=function(){this.value=32;} </script> </head> <body> <input type=text name="ssn" id="ssn" value="" /> </body> <html>
 提示:您可以先修改部分代码再运行
但是
<input type=text name="ssn" id="ssn" value="" onclick=""javascript:this.value=32;"  />
这样是可以的,但我不想混编,那我要杂写代码才行啊

[ 本帖最后由 cloudgamer 于 2010-6-7 13:37 编辑 ]

作者: iminto   发布时间: 2010-06-06

顶一下,求助

作者: iminto   发布时间: 2010-06-06

注意顺序!
如果没有指定onload以后执行,JS脚本是按照下载顺序执行的!
你写的那段,当JS执行的时候,input还不存在!
<html> <head> </head> <body> <input type=text name="ssn" id="ssn" value="" /> <script> var $=function(ids){ return document.getElementById(ids); } $("ssn").onclick=function(){this.value=32;} </script> </body> <html>
 提示:您可以先修改部分代码再运行

作者: fonqing   发布时间: 2010-06-06

谢谢了,迷惑了我半天,哎,好人啊

作者: iminto   发布时间: 2010-06-07

又有新问题了
<INPUT id="btn_s" src="image/check.png" type=image name="submit" style="width:32px;height:32px; border:none" /> <script> $("btn_s").onclick=function(){ajax('check','check','check.php','result');}//没效果 $("btn_s").onclick=ajax('check','check','check.php','result');//没效果 </script>
 提示:您可以先修改部分代码再运行
但是
<INPUT id="btn_s" src="image/check.png" type=image name="submit" style="width:32px;height:32px; border:none" onclick="ajax('check','check','check.php','result');"/>
这样是有的,该怎么修改啊

作者: iminto   发布时间: 2010-06-07


<INPUT id="btn_s" src="http://bbs.blueidea.com/images/default/logo.gif" type=image name="submit" style="width:32px;height:32px; border:none" /> <script> var $=function(ids){ return document.getElementById(ids); } $("btn_s").onclick=function(){alert("有效果")} </script>
 提示:您可以先修改部分代码再运行

作者: hsb008   发布时间: 2010-06-07

我刚开始的时候也经常犯这种错误

作者: AyumiHamasaki   发布时间: 2010-06-07

诡异啊,上面的代码是可以的。但是我放在我的网页里就不行了。在BODY最后面放上
<script>
var seria=cookie("ssn");
$("ssn").onclick=function(){this.value=seria;}
</script>
死活就是无效,郁闷啊。

作者: iminto   发布时间: 2010-06-07

热门下载

更多