为什么这在 IE/Chrome 中不起作用,但在 FF/Opera 中起作用?我想让锚点周围的 div 可以点击,这样当你点击 div 时,它的行为就像你点击锚点本身一样。
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function bindOnClickPostBack() {
$(".header a").each(function () {
var anchor = $(this);
var clickEvent = anchor.attr('href');
var header = anchor.parent();
header.css('background-color', 'yellow');
header.attr('onclick', clickEvent);
});
/*$(".header").live("click", function(){
anchor = $(this).find('a');
var clickEvent = anchor.attr('href');
alert(clickEvent);
$(this).css('background-color', 'yellow');
//header.attr('onclick', clickEvent);
//anchor.click();
});*/
return false;
}
$(document).ready(function() {
bindOnClickPostBack();
});
</script>
身体:
<div style="background-color:red" class="header"> <a href="alert('hello1')">Shortcut1</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello2')">Shortcut2</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello3')">Shortcut3</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello4')">Shortcut4</a></div>