Delegate doesn't works on IE? A very strange behaviour
I notice that this my own page doesnt work at all on IE8 : try to click on Add Category
, than on Create Category
: you should get an alert. In fact that's not happens on my IE8. Chrome, Firefox, all ok.
Why? This is the whole code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The GTW Database</title>
<script type="text/javascript" src="settings/jquery-1.5.min.js"></script>
<script type="text/javascript" src="mgmt/mgmt_javascript.js"></script>
<link type="text/css" rel="stylesheet" href="settings/style.css" title="Style" media="all" />
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$('#addCategory').click(function(e) {
e.preventDefault();
$('#addCategoryForm').toggle();
});
$("#addCategoryForm").delegate("form[name=categoryForm]", "submit", function(e){
e.preventDefault();
alert("Yeah, I'm In");
});
开发者_开发百科 });
</script>
<div class="main_content_remark">
<div class="back1">
Categories
</div>
<div class="back2">
<a id="addCategory" class="lblueb" href="#">Add Category</a>
</div>
</div>
<div class="main_content_remark" id="addCategoryForm" style="display:none; height:32px;">
<form method='post' name="categoryForm">
<div class="categoryName">
<div class="categoryName1">
Name
</div>
<div class="categoryName2">
<input type="text" maxlength="50" name="name" class="input400" />
</div>
<div class="categoryName3">
</div>
<div class="categoryName4">
<input type="submit" value="Create Category" />
</div>
</div>
</form>
</div>
</body>
Hope you can help me. It's really strange... the same method works perfectly in other pages...
The problem is that you are using the [name=categoryForm]
which confuses IE7,8. Change it to an ID or if this form is the only form inside #addCategoryForm
then just write:
$("#addCategoryForm").delegate("form", "submit", function (e) {
e.preventDefault();
alert("Yeah, I'm In");
});
精彩评论