作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法在提交时调用 jQuery。函数中的警告不显示。
我想显示所有选中的复选框名称的警报。
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready({
$("#roleManagement").submit(function() {
alert("hi");
var selected = new Array();
$('#checkboxes input:checked').each(function() {
selected.push($(this).attr('name'));
});
$.each(selected, function(key, value) {
alert(key + ": " + value);
});
});
</script>
<body>
<form method="post" id="roleManagement">Role Id
<input type="text" name="roll_id" />
<br>Role Name
<input type="text" name="roll_name" />
<br>Role Description
<textarea name="roll_desc"></textarea>
<br>
<br>
<br>
<div id="checkboxes">Screen1
<br>tab1
<br>
<input type="checkbox" name="s1_t1_view" value="s1_t1_view" checked="checked >view<br>
<input type=" checkbox " name="s1_t1_add " value="s1_t1_add " >add<br>
<input type="checkbox " name="s1_t1_edit " value="s1_t1_edit " >edit<br>
<input type="checkbox " name="s1_t1_delete " value="s1_t1_delete " >delete<br>
tab2<br>
<input type="checkbox " name="s1_t2_view " value="s1_t2_view " >view<br>
<input type="checkbox " name="s1_t2_add " value="s1_t2_add " >add<br>
<input type="checkbox " name="s1_t2_edit " value="s1_t2_edit " >edit<br>
<input type="checkbox " name="s1_t2_delete " value="s1_t2_delete " >delete<br>
Screen2<br>
tab1<br>
<input type="checkbox " name="s2_t1_view " value="s2_t1_view " >view<br>
<input type="checkbox " name="s2_t1_add " value="s2_t1_add " >add<br>
<input type="checkbox " name="s2_t1_edit " value="s2_t1_edit " >edit<br>
<input type="checkbox " name="s2_t1_delete " value="s2_t1_delete " >delete<br>
tab2<br>
<input type="checkbox " name="s2_t2_view " value="s2_t2_view " >view<br>
<input type="checkbox " name="s2_t2_add " value="s2_t2_add " >add<br>
<input type="checkbox " name="s2_t2_edit " value="s2_t2_edit " >edit<br>
<input type="checkbox " name="s2_t2_delete " value="s2_t2_delete " >delete<br>
</div>
<input type="submit " name="sumbit " text="submit ">
</form>
</body>
</html>
我哪里错了?
最佳答案
你的脚本不合适,你需要传递一个函数作为参数给ready()
$(document).ready(function() {
$("#roleManagement").submit(function() {
alert("hi");
var selected = new Array();
$('#checkboxes input:checked').each(function() {
selected.push($(this).attr('name'));
});
$.each(selected, function(key, value) {
alert(key + ": " + value);
});
})
});
关于jquery - 如何在提交时调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16544782/
我是一名优秀的程序员,十分优秀!