IE5中用JavaScript跨frame加option问题

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 abigfrog 的 blog

跨frame加option,以下代码在ie5中会出错,但在ie4、ie6、opera6、nnx中都没有问题:

<script>
function addoption(aselect, optionid, optionname) {
    newoption = new option(optionname, optionid);
    aselect.options[aselect.options.length] = newoption;
}
</script>


这样才是对的:
<script>
function addoption(aselect, optionid, optionname) {
    ownerwindow = aselect.document.parentwindow;
    ownerwindow.newoption = new option(optionname, optionid);
    aselect.options[aselect.options.length] = ownerwindow.newoption;
}

function crossframeaddoption() {
    var aselect = parent.otherframename.document.forms[0].theselectname;
    addoption(aselect , "id"+ aselect.options.length, "name"+ aselect.options.length);
}
</script>
<input type="button" onclick="crossframeaddoption();" value="test">

微软的解释如下: in general, at least in the older browser versions, performance seems to improve if you call methods on the target frame if they are stored there as well. this is particularly relevant when trying to add options to a select box in another frame. make sure you create the option in that other frame so you are adding it to a local select box, instead of trying to cross frame boundaries.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebteam/html/webteam02052002.asp

本文关键:selectbox javascript frame 框架 选择框
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top