当前位置: 首页 > 图文教程 > 网络编程 > Javascript > IE5中用JavaScript跨frame加option问题

Javascript
图片展示效果 鼠标经过变大图,支持FF
可拖动可改变大小div的实现代码
javascript 随机广告代码(图片广告)
JS+Ajax+Jquery实现页面无刷新分页以及分组 超强的实现
JQuery 浮动导航栏实现代码
jQuery一步一步实现跨浏览器的可编辑表格,支持IE、Firefox、Safari、Chrome、Opera
js 分栏效果实现代码
基于jQuery的ajax功能实现web service的json转化
IE 条件注释详解总结(附实例代码)
用cssText批量修改样式
JavaScript 应用技巧集合[推荐]
jquery 导航设计实现代码 学习jquery的朋友可以看下
动态样式类封装JS代码
一步一步教你写一个jQuery的插件教程(Plugin)
使用jQuery的ajax功能实现的RSS Reader 代码
jquery tools 系列 scrollable(2)
jquery tools系列 overlay 学习
jquery tools系列 expose 学习
javascript十个最常用的自定义函数(中文版)
javascript 流畅动画实现原理

Javascript 中的 IE5中用JavaScript跨frame加option问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 198 ::
收藏到网摘: n/a

跨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