jquery 控制frameset frame节点内容(在子窗口中把该窗口中的焦点处的text内容填

现在做这个项目中,有一项把:在子窗口中把该窗口中的焦点处的text内容填入其它子窗口的input内,也就是改写input的value值,这个费了4天时间,写下来记录一下心情吧

这个问题困扰了我4天,今天终于解决了,其实这并不难,只是自己学的太少,边学边用,又费时间又费精力,但真是长知识。

在left中访问right中的对象的jquery代码为:


$(window.parent.parent.frames["right"].document).find('#jh')这是找到了ID为jh的对象

$(window.parent.parent.frames["right"].document).find('#jh').val是指的是id对象的value值。


在left中访问right中的对象,并将left表格中的值传给righ中id为jh的文本框的代码为:

在left.php中的html代码为:

<td><a href="#" class="style1" onClick="MM_changeProp(this)" ><?php echo "$row[$i]"; ?></a></td>//点击触发MM_changeProp事件,并将此时,焦点处的text内容传给函数。

javascript部分是:

[javascript]  view plain copy print ?
  1. <span style="color:#ff6666;">   function MM_changeProp(leftjhObj) {//带参数的函数,把焦点对象传给函数  
  2.         leftjh=leftjhObj.innerText;//得到了焦点对象的text属性,也就是表格中的内容  
  3.         rightjh=$(window.parent.frames["right"].document).find('#jh').val(leftjh);}//取得right框架中的id为jh的对象的val值,并改变为焦点的内容,这样就实现了把一个子框架的值传给另一个框架了,这里我一直把值以=的形式改写,所以才一直无法得正确传值。我用的是:</span>  
[javascript]  view plain copy print ?
  1. <pre name="code" class="javascript"><span style="color:#ff6666;">rightjh=$(window.parent.frames["right"].document).find('#jh').val()=<span style="font-family: Arial, Helvetica, sans-serif;">leftjh;这是错误的,要把值通过val()方法传给对象才行。</span></span></pre>  
  2. <pre></pre>  
  3. <p></p>  
  4. <p>主框架代码为:</p>  
  5. <pre name="code" class="html"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
  6. <html xmlns="http://www.w3.org/1999/xhtml"></pre><pre name="code" class="html"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></pre><pre name="code" class="html"><title>jquery 控制frameset frame节点内容</title></head></pre><pre name="code" class="html"><frameset rows="*" cols="217,*"></pre><pre name="code" class="html">  <frame name="left" src="left1.php" noresize="noresize" /></pre><pre name="code" class="html">  <frame name="right" src="right1.php" /></frameset><noframes><body></body></noframes></html>  
  7. 在右边的框架中,有一个form表单中有一个ID为jh的<input type="text" id="jh">  
  8. <form action="" method="POST"></pre><pre name="code" class="html"><table></pre><pre name="code" class="html"><tr></pre><pre name="code" class="html"><span style="white-space:pre">   </span><tb>  
  9.  <span style="white-space:pre">     </span><input  type="text" id="jh"/></tb>  
  10. <pre name="code" class="html"><span style="white-space:pre">    </span></tr></pre> <pre name="code" class="html"><span style="white-space:pre">   </span><tr></pre><pre name="code" class="html"><span style="white-space:pre"> </span><tb></pre><span style="white-space:pre"></span><input type="submit"/ value="提交><pre name="code" class="html"><span style="white-space:pre">  </span></tb></pre>  
  11. <pre></pre>  
  12. <pre name="code" class="html"><span style="white-space:pre">    </span></tr></pre><pre name="code" class="html"></table>  
  13. </form></pre><br>  
  14. <br>  
  15. <p></p>  
  16. <pre></pre>  
  17. <pre></pre>  
  18. <pre></pre>  
  19. <pre></pre>  
  20.   
  21. </pre>  

你可能感兴趣的:(jquery,frame,FRAMESET)