现在有一个父界面,用的是jquery easyui的lay-out框架。
每点击不同的按钮就会用js动态添加一个tab,每个tab中包含一个iframe页面var content = '<iframe name="1" scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';问题是:怎么根据点击的按钮来给每个iframe页面赋值呢
iframe中的代码如下:  <body>
        <div class="div-margin-bottom" id="title">标题:<input id="caption" name="caption" style="width:400px;"/></div>
        <p>内容:</p>
        <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10">
        </textarea>
            <p>
                <input id="submit" type="button" value="Submit" onclick="test();"/>
            </p>
  </body>

解决方案 »

  1.   

    Jquery中不是有append方法嘛,用这个拼接
      

  2.   

    我问的是怎么给iframe中的input和ckeditor赋值呀
      

  3.   

    在父页面写个方法,返回你要的值,然后在iframe里调parent.你写的方法 就行了
      

  4.   

    额额,不好意思,没仔细看,这样
    你用Jquery先把content封装成JQuery对象,再用attr给属性赋值应该可以吧
    对象转换直接用$(content)就可以了
      

  5.   

    给iframe一个id吧,可以使用父页面的document对象获取到iframe的document对象
    var zdoc = document.frames[id].document;
    zdoc.getElementById('caption').value = ...
    就可以了
      

  6.   

    我的iframe是在父界面中动态加载的,是不是得确保iframe完全加载完之后才能用你说的代码呢,还有怎么确保iframe已经完全加载完成了呢
      

  7.   

    如果是父页面一加载就运行JS,是需要判断iframe是否加载完毕的。使用以下代码可以做判断加载情况: if(iframeWindow.document.readyState  == 'complete'){
    //已经加载完,这里赋值
    }else{
                    //没有加载完,则每次加载状态改变时都判断一下
    iframeWindow.document.onreadystatechange = function(){
    if(iframeWindow.document.readyState  == 'complete'){
    //已经加载完,这里赋值
    }
    };
    }
    iframeWindow就是你取到的那个iframe页面的window对象。