标题基本不能表达我想表达的确切意思,嘿嘿 把代码贴出来,
有达人请指点一下
a.html,b.html,jquery.js在同一个文件夹
注意有用到jquery,代码这里就不提供了
a.html代码如下<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $(".ctt").click(function(e1){
$("#s3").val($(this).attr("gid"));
 });
});
</script><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<p>
  <label>
    <input class="ctt" type="submit" name="s1" id="s1" value="1111111111" gid="gid1111111111" />
    <input class="ctt" type="submit" name="s4" id="s4" value="4444444444" gid="gid44444444444" />
  </label>
</p>
<p>
  <label>
    <input name="s3" type="text" id="s3" value="opopopopophhh" />
  </label>
</p>
<iframe src="b.html"></iframe>
</body>
</html>
b.html代码如下<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("#s2").click(function(e1){

$(window.parent.document).find("#s4").attr("gid","gid2222222");
alert($(window.parent.document).find("#s4").attr("gid"));
$(window.parent.document).find("#s4").click();
 });
});
</script>
<body>
<label>
  <input type="submit" name="s2" id="s2" value="调用a页面中s1按钮的click动作" />
</label>
</body>
</html>我预计的效果是
单击b页面中的按钮s2,a页面中文字框s3中的值应该是 gid2222222
但是不是,不知道怎么回事。但是我如果直接删除a页面中的s1按钮,这样效果就符合我的预计了为什么会这样,怎样才能不删除s1也能让效果符合我的预计?

解决方案 »

  1.   

    这个是两个环境之间的交互。
    把iframe的id设为iframe_1
    然后修改你的s4执行代码     $(".ctt").click(function(e1){
    if ( $.browser.msie&&+$.browser.version<8 ){//低于ie8的浏览器处理
    document.frames["iframe_1"].$("#submit").val("这绝对是你想要的");
    }else{
    $("#iframe_1").contentWindow..$("#submit").val("这绝对是你想要的");
    }
         });
      

  2.   

    解决了 两方面问题1.要给onclick事件在适当位置设置 return false; 或者 return void(0); 否则不知道事件什么时候停止。
    2.至于“按钮“才确保能对设置的 click事件有反应