【发布时间】:2015-01-26 07:57:06
【问题描述】:
我是 C++ 程序员,是 JS World 的新手。
这是指我之前的问题。
How to submit form based on certain condition?
我正在尝试根据特定条件使用 document.getElementById 提交我的表单,但没有输出。
<!doctype html>
<html lang="en">
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<title>jQuery.post demo</title>
<body>
<meta charset="utf-8">
<div id="form-container" style="padding-top: 10px; padding-bottom: 10px;">
<script>
var x=Math.random();;
if(x > 0.5)
{
//document.writeln(x);
document.getElementById('form-container').submit();
}
</script>
X Value: <input type="text" name="X"><br>
<br>
<p style="text-align: left;"><button type="button" id="submit-button">Submit</button></p>
</div>
</body>
<script>
$(document).ready(function(e) {
$('#submit-button').click(function(event){
$('#form-container').submit();
)};
)};
</script>
</html>
【问题讨论】:
-
我在您的代码中没有看到表单元素。
-
答案是你的标签之一,你需要
<form>
标签: javascript php jquery html forms