脚本宝典收集整理的这篇文章主要介绍了php – 使用JavaScript获取表单变量,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<form id=\"form1\" name=\"form1\" method=\"\" action=\"JavaScript:alterRecord()\"> <input name=\"radiobutton\" tyPE=\"radio\" value=\"test1\" />test 2<p> <input name=\"radiobutton\" type=\"radio\" value=\"test2\" />Test 2<p> <input name=\"radiobutton\" type=\"radio\" value=\"test3\" />Test 3<p> <input name=\"radiobutton\" type=\"radio\" value=\"test4\" />Test 4 <input type=\"submIT\" name=\"Submit\" value=\"Submit\" /> </form>
还有JavaScript
function alterRecord(value) { alert(value); }
<htML> <head> <style type="text/css"> body { background-color: black; color: white; } </style> <script type="text/javascript"> function handleClick(event) { if (console) console.info("handling click"); // for Firebug debugging,if you want it /* do something here */ alert(this.textBox1.value); // I don't like alerts but it works everywhere if (console) console.info("handled click"); event.preventDefault(); // disable normal form submit behavior return false; // PRevent further bubbling of event } function doit() { if (console) console.info("starting doit()"); document.forms.myform.addEventListener("submit",handleClick,true); return true; } </script> </head> <body onload="doit()"> <form name="myform"> <div> <textarea name="textBox1" rows="10" cols="80"> 'Twas brillig,and the slithy toves Did gyre and gimble in the wabe; All mimsy were the borogoves,And the mome raths outgrabe. </textarea> </div> <input type="submit" value="Update"/> </form> </body> </html>
行event.preventDefault()和返回false是键.我也喜欢使用addEventListener,而不是在表单中硬编码onSubmit.我想,这只是风格/偏好的问题. (尽管addEventListener允许您拥有多个处理程序.)
以上是脚本宝典为你收集整理的php – 使用JavaScript获取表单变量全部内容,希望文章能够帮你解决php – 使用JavaScript获取表单变量所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。