怎么使<input type="hidden">的value发生变化时运行方法 我想让<input type="hidden">的value发生变化时运行一个方法,但是他没有onchange事件,求高手指点怎么弄 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 onpropertychange 试试 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <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="hidden" id="h" onpropertychange="test()"/> <input type="button" id="b" onclick="foo()" value="clickme"/> </body> <script> function foo(){ document.getElementById("h").value+="1" } function test(){ alert(document.getElementById("h").value) } </script></html> <input type="hidden">的值什么时候会改变?它又不像文本框,可以在键盘或鼠标事件中发生变化。一般只有一种情况会改变它的值:那就是你自己写脚本代码改变的。既然这样的话,完全无需使用监听事件的方式来处理,直接在改变其值的代码后面接着写即可。 是的,不过你确实想改变的话,就用脚本控制好了。给它添加监听事件<input type='hidden' id='hi'>jq:$("#hi").bind("click",fun(){alert("ok")}) 这位老兄真逗,你可曾用鼠标点到过hidden元素? 我这是一个jsp页面,有好多<input type="hidden" >,被触发的方法的参数是不同的,onpropertychange(‘<%=参数一%>’,‘<%=参数二%>’,this.value),使这个hidden域的value值变化的那个方法是写在<script></script>里面的,参数变不了啊。 不好意思,写错了是<input type="hidden" onpropertychange=fun(‘<%=参数一%>’,‘<%=参数二%>’,this.value)> 你可以将两个“参数”连同 input:hidden 之前的 value 并在一起,然后作为新的 value。如果你觉得这样会影响提交到服务端的数据,那也可以将“参数”写在其它标签属性内:<input type="hidden" arg1="<%=arg1%>" arg2="<%=arg2%>" />然后在脚本中可以取元素属性:var arg1 = oInput.getAttribute('arg1');var arg2 = oInput.getAttribute('arg2'); 文本框自动搜所和现实 Javascript 类扩展问题 大家请帮忙看看这个问题,谢谢了! 请问如何得到一个网页中的form对象? 项目外包,认为自己是js牛人的请联系 我如何得到页面上所有超级连接的对象 怎样判断文本框不能为空以及只能为数字? 请问这个javascript怎么不对呀 关于js程序处理先后问题? 如何抓取网站加密压缩后的数据? 求指教:一段JS代码,在IE中总报错缺少对象 ckeditor 无法获取内容
<html>
<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="hidden" id="h" onpropertychange="test()"/>
<input type="button" id="b" onclick="foo()" value="clickme"/>
</body>
<script>
function foo(){
document.getElementById("h").value+="1"
}
function test(){
alert(document.getElementById("h").value)
}
</script>
</html>
它又不像文本框,可以在键盘或鼠标事件中发生变化。
一般只有一种情况会改变它的值:那就是你自己写脚本代码改变的。既然这样的话,完全无需使用监听事件的方式来处理,直接在改变其值的代码后面接着写即可。
<input type='hidden' id='hi'>
jq:$("#hi").bind("click",fun(){alert("ok")})
不好意思,写错了
是<input type="hidden" onpropertychange=fun(‘<%=参数一%>’,‘<%=参数二%>’,this.value)>
<input type="hidden" arg1="<%=arg1%>" arg2="<%=arg2%>" />
然后在脚本中可以取元素属性:
var arg1 = oInput.getAttribute('arg1');
var arg2 = oInput.getAttribute('arg2');