我想让<input type="hidden">的value发生变化时运行一个方法,但是他没有onchange事件,求高手指点怎么弄

解决方案 »

  1.   

    onpropertychange 试试 
      

  2.   

    <!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>
      

  3.   

    <input type="hidden">的值什么时候会改变?
    它又不像文本框,可以在键盘或鼠标事件中发生变化。
    一般只有一种情况会改变它的值:那就是你自己写脚本代码改变的。既然这样的话,完全无需使用监听事件的方式来处理,直接在改变其值的代码后面接着写即可。
      

  4.   

    是的,不过你确实想改变的话,就用脚本控制好了。给它添加监听事件
    <input type='hidden' id='hi'>
    jq:$("#hi").bind("click",fun(){alert("ok")})
      

  5.   

    这位老兄真逗,你可曾用鼠标点到过hidden元素?
      

  6.   

    我这是一个jsp页面,有好多<input type="hidden" >,被触发的方法的参数是不同的,onpropertychange(‘<%=参数一%>’,‘<%=参数二%>’,this.value),使这个hidden域的value值变化的那个方法是写在<script></script>里面的,参数变不了啊。
      

  7.   


    不好意思,写错了
    是<input type="hidden" onpropertychange=fun(‘<%=参数一%>’,‘<%=参数二%>’,this.value)>
      

  8.   

    你可以将两个“参数”连同 input:hidden 之前的 value 并在一起,然后作为新的 value。如果你觉得这样会影响提交到服务端的数据,那也可以将“参数”写在其它标签属性内:
    <input type="hidden" arg1="<%=arg1%>" arg2="<%=arg2%>" />
    然后在脚本中可以取元素属性:
    var arg1 = oInput.getAttribute('arg1');
    var arg2 = oInput.getAttribute('arg2');