html结构如下:
1
<
html
>
2
<
head
>
3
<
title
>
为body添加click事件
</
title
>
4
<
meta
http-equiv
="content-type"
content
="text/html;charset=utf-8"
>
5
<
script
type
="text/javascript"
src
="jquery-1.5.2.js"
></
script
>
6
<
script
>
7
function
show_body_click(){
8
alert(
'
you are click the body
'
);
9
}
10
jQuery(document).ready(
function
(){
11
//
jQuery("ifr_id").contents().find("body").attr("onclick", "show_body_click()");
12
//alert(jQuery(
"
#ifr_id
"
).contents().find(
'
body
'
).attr(
"
onclick
"
,
'
xxxx()
'
));//不能实现
13
//
var ifr = jQuery("ifr_id")
14
});
15
jQuery(document,
'
#ifr_id
'
).ready(
function
(){
16
jQuery(
"
#ifr_id
"
).contents().find(
"
body
"
).attr(
"
onclick
"
,
"
parent.show_body_click()
"
);
17
//
jQuery("#ifr_id").contents().find("body").live("click", "parent.show_body_click()");//ff没有效果
18
//
jQuery("#ifr_id").contents().find("body").click(parent.show_body_click()); //ff没有效果
19
});
20
21
</
script
>
22
</
head
>
23
<
body
id
="body_id"
>
24
<
span
>
25
<
iframe
id
="ifr_id"
src
="eval.html"
height
="100px"
width
="800px"
></
iframe
>
26
</
span
>
27
</
body
>
28
</
html
>