【发布时间】:2017-04-09 23:43:23
【问题描述】:
我有这个 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<title>Modal</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="modalUI.css">
<script src="jquery-3.1.1.js"></script>
<script src="jquery-3.1.1.min.js"></script>
<link rel="stylesheet" href="jquery-ui-1.12.1.custom/jquery-ui.min.css">
<script src="jquery-ui-1.12.1.custom/external/jquery/jquery.js"></script>
<script src="jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#create-user').click(function(){
$('#dialog').dialog("open");
});
$('#dialog').dialog({
draggable: true,
resizable: false,
closeOnEscape: true,
modal: true,
autoOpen: false
});
});
</script>
</head>
<body>
<form id="form1">
<table class="table table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
</tbody>
</table><br>
<input type="button" value="Show Dialog" id="create-user"/>
<div id="dialog" title="Create new User">
<form id="form2" action="">
<label for="name">FirstName</label><br>
<input type="text" name="fname" ><br>
<label for="lastname">LastName</label><br>
<input type="text" name="lname" ><br>
<label for="email">Email</label><br>
<input type="email" name="email" ><br><br>
<button type="submit" value="Submit" id="submitDemo">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</div>
</form>
</body>
</html>
弹出对话框时,我的提交按钮不起作用。我应该在我的 jQuery 上写什么? p.s 提交在 div 对话框之外工作。但是如何让它在对话框中起作用呢?
不要介意这个 lorem ipsum 的事情。 (Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 Ut enim ad minim veniam, quis nostrud 练习 ullamco laboris nisi ut aliquip ex ea commodo 结果。 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Exceptioneur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est labourum。)
【问题讨论】:
-
你把$(document).ready(function(){的括号合起来了吗?
-
为什么在提交按钮点击时调用 submit() 函数?它应该被自动调用。
-
@Vaidas
<button type="submit",OP 的代码已经具有的功能与您的建议完全相同。 -
你包含 jQuery 3 次。您可以删除后两个。您还包括两次 jQueryUI,删除第一个(非“.min.js”)。还有一个不匹配的
form标签会导致问题,需要删除。 -
@MattCowley 是的,你是对的。我错过了结束标签,因为它的格式不明确。 OP:嵌套表单不是有效的 HTML。