我有一个包含几个 div 和其他元素的 iframe。我想将焦点设置到几个文本框中的一个文本框。
我用了:
a = iFrameObj.contentWindow.document.getElementById('myTxtBox');
But here, a is null;
我可以使用以下代码访问文本框对象;
var myTextBox = iFrameObj.contentWindow.document.getElementsByTagName('input')[52];
但我想使用更通用的方法来获取对象而不是硬编码索引。
由于此文本框具有唯一的类名,因此我尝试了以下代码:
var myTextBox = iFrameObj.contentWindow.document.getElementsByClassName('rgtxt')[0];
但我错误:
"Object does not support this property or method"
我的文本框的 HTML 是:
<input name="myTxtBox" type="text" class="rgtxt" id="myTxtBox" value="hello" style="display:block;color:Black;background-color:rgb(240, 241, 241);" readonly="readonly" />
有人可以帮助 iFrame 这两种方法有什么区别吗?