<form id="form" name="form" method="post" action="">
<input name="code" type="text" size="30" id="code" onblur="jianche()">
</form>
这个时候我想得到表单code值可以使用
<script language="javascript">
function jianche(){
alert(form.code.value);  //这个时候我想用this实现同样的功能,form.code.value改成this.value吗?
}
</script>
想通过this实现一样的功能,具体怎么做

解决方案 »

  1.   

    <form id="form" name="form" method="post" action="">
    <input name="code" type="text" size="30" id="code" onblur="jianche(this)">
    </form>
    这个时候我想得到表单code值可以使用
    <script language="javascript">
    function jianche(codeObj){
    alert(codeObj.value);  //这个时候我想用this实现同样的功能,form.code.value改成this.value吗?
    }
    </script>
      

  2.   

    不是的
    <form id="form" name="form" method="post" action="">
    <input name="code" type="text" size="30" id="code" onblur="jianche(this)">
    </form>
    这个时候我想得到表单code值可以使用
    <script language="javascript">
    function jianche(obj){ //这个obj就是onblur里那个this 就是元素本身
    alert(obj.value);  //
    }
    </script>
      

  3.   

    给lz个this学习参考
    http://topic.csdn.net/u/20090217/13/653f7949-9e0c-4e99-adb3-dcbc99fca8d5.html?23306
      

  4.   

    <form id="form" name="form" method="post" action="">
    <input name="code" type="text" size="30" id="code">
    </form>
    这个时候我想得到表单code值可以使用
    <script language="javascript">
    document.getElementById("code") = function jianche(){
    alert(this.value);  //这个时候我想用this实现同样的功能,form.code.value改成this.value吗?
    }
    </script>