我设计了如下的测试代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(function(){
//alert($("form select,:input").size());
$(':submit').click(function(){
var obj=$(this).closest("form");
alert($(obj).is("form"));
return false;
});
});
</script>
</head>
<body>
<table width="500" border="1" cellspacing="1" cellpadding="2">
<form id="form1" name="form1" method="post" action="#1">
<tr>
<td><input type="text" name="textfield" id="textfield" /></td>
</tr>
<tr>
<td><textarea name="textarea" id="textarea" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" id="checkbox" /></td>
</tr>
<tr>
<td><select name="select" id="select">
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="button" id="button" value="提交" /> </td>
</tr></form>
</table>
使用opera浏览器:
当form标签在table内部时,使用JQUERY的closest函数从submit标签开始无法获取到form标签,使用parent标签,从submit标签开始向上套取,获取到的是td,tr,tbody,table跳过了form标签。
使用ie浏览器一切正常,这是为何啊?哪位高手能测试下。
各位高手,可以复制我的代码,分别在两种不同的浏览器下测试下,会出现不同的结果,IE能正常给出true对话框,但是OPERA只能给出FALSE对话框。
一试便知结果~~