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

Javascript
网页常用小技巧—javascript篇
中文的版用javascript实现超酷的“网页时钟”
60秒倒计时的一个小javascript
一步一步教你用JS和INF编辑注册表
仿Office 2003的工具条
javascript加密解密终级指南
在网页里做类似window右键的弹出式菜单
几行代码轻松搞定网页的简繁转换
利用Yahoo! Search API开发自已的搜索引擎-javascript版
服务器控件中js脚本注册方法
一行代码生成Google SiteMap
用javascript连接access数据库的方法
javascript+xml实现二级下拉菜单,不会被任何标签或元素遮住
javascript的IE和Firefox兼容性汇编
TreeView节点互斥,autopostback=false的方法
一个解析URL及图片地址的JS函数
javascript模拟ACDSEE简单功能
实现textarea内字符串选择查询替换功能
javascript Web页面内容导出到Word、Excel
在客户端设置cooke和获取cooke的函数

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 188 ::
收藏到网摘: 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