我想使用html和javascript(严格禁止使用php)具有html数据输入表单,以将数据传递给js,以另存为变量。任何帮助,将不胜感激 :)
到目前为止,这是什么:
<form id="myform"> //form name
What is your name: <input type='text' name='name'> //name input
<a href="javascript: formCatch(name)">Go</a> // running some kind of function?
</form>
然后是js端
var name = 'test';
function formCatch() { //declare function 'formCatch'
name = document.forms["myform"].submit(); // set the name variable as the contents from the form
alert('hello, ' + name); // alert to test the output
}
我很确定该函数的第二行是不正确的。
我在该函数中寻找的是将输入到html页面上的表单中的数据另存为name变量。
也许这就是您要寻找的:
<script>
var name = 'test';
function formCatch() {
document.forms["myform"].submit();
name = document.getElementById("name").value;
alert('hello, ' + name);
}
</script>
<form id="myform">
What is your name: <input id="name" type='text' name='name'>
<a href="javascript:formCatch();">Go</a>
</form>
观看这个演示
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句