域名注册|域名申请|域名空间|空间租用|虚拟主机租用
中域互联诚意为您提供域名注册、虚拟主机等网络服务,欢迎光临,热线:020-32676839、32696039
118 繁體中文 118 联系我们    118 关于我们    118 建站信息中心    118 显示在线咨询
118
118
虚拟主机

IE5中用JavaScript跨frame加option问题

javascript 点击次数:617

跨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.

 

欢迎转载《IE5中用JavaScript跨frame加option问题》,请保留出处。
返回首页 | 关于我们 | 联系我们 | 付款方式118 | 帮助中心 | 提问帮助 | 中域互联招聘 网站地图 建站信息中心
客服1号:619086478 客服2号:759043498 客服3号:419602084 客服4号:707187709
技术1号:502825590 技术2号:609223275 技术3号:347054506 网站备案:626709096
电话:020-32676839、32696039、32651958 传真:020-32677208 邮件和MSN:service@118cy.net 118
广州市炬正通信技术有限公司 地址:广州市黄埔大道中员村白马岗街艾琳大楼406 邮编:510655 
《中华人民共和国增值电信业务经营许可证》ISP证编号:粤B2-20080048  粤ICP备07025283号
广州虚拟主机提供商-中域互联营业执照