我看不出有什么问题,submit()
不再有效了吗?
<html>
<head>
<title>This is the title</title>
<script type = "text/javascript">
function onLoad() {
document.getElementById("input1").value="text1";
document.getElementById("input2").value="text2";
document.getElementById('form').submit();
}
</script>
</head>
<body onload="onLoad();">
<form method="post" name="form" id="form" action="test.txt">
<label for="input1">Input1</label> <input id="input1" name="input1" type="text"/>
<label for="input2">Input2</label> <input id="input2" name="input2" type="text"/>
<input name="submit" id="submit" value="submit" type="submit"/>
</form>
</body>
</html>
答案 0 :(得分:2)
如果您没有name
修改提交按钮submit
这会破坏方法定义
答案 1 :(得分:2)
您的问题是该按钮名为submit并且hs id提交。改变它,它的工作原理。 您使用提交按钮元素覆盖了提交功能。
答案 2 :(得分:-1)
尝试这个..
<html>
<head>
<title>This is the title</title>
<script type = "text/javascript">
function Test() {
document.getElementById("input1").value="NewValue1";
document.getElementById("input2").value="NewValue2";
document.getElementById('form').submit();
}
</script>
</head>
<body onload="Test();">
<form method="post" name="form" id="form" action="new.html">
<label for="input1">Input1</label> <input id="input1" name="input1" type="text"/>
<label for="input2">Input2</label> <input id="input2" name="input2" type="text"/>
<input name="submit" id="submit" value="submit" type="submit"/>
</form>
</body>
</html>