javascript函数在IE 7中不起作用

编程入门 行业动态 更新时间:2024-10-24 18:25:31
本文介绍了javascript函数在IE 7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都可以告诉我如何在IE 7中运行此脚本?当我运行它时,没有任何反应。

Can anyone please tell me how do I make this script run in IE 7? When I run this , nothing happens.

<html> <head> <script language="JavaScript"> function moveSelectedOption() { // Fetch references to the <select> elements. var origin = document.getElementById('origin_select'); var target = document.getElementById('target_select'); // Fetch the selected option and clone it. var option = origin.options[origin.selectedIndex]; var copy = option.cloneNode(true); // Add the clone to the target element. target.add(copy, null); } </script> </head> <body> <select id="origin_select" multiple> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> <select id="target_select" multiple> <option value="C1">C1</option> </select> <button onclick="moveSelectedOption()">Add</button> <!-- <input type="button" onClick="moveSelectedOption()" value="AddMeToo" /> this does not work either--> </body> </html>

推荐答案

尝试

var origin = document.getElementById('origin_select'); var target = document.getElementById('target_select'); // Fetch the selected option and clone it. var option = origin.options[origin.selectedIndex]; target.options[target.options.length] = new Option(option.text, option.value);

如果你想从原因选择元素中删除该选项,那么你可以使用这个

If you want to remove the option from the origin select element then you can use this

origin.remove(option);

没有移动的演示

Demo without move

移动演示

Demo with move

编辑

Edit

此行导致错误。

target.add(copy, null);

add()不适用于标准秒在资源管理器中的参数,即使值为null,所以为了兼容,可以尝试双参数版本,并且在失败时,使用单参数版本。 / p>

add() does not work with the standard second argument in Explorer, even with value null, so in order to be compatible one may try the two-argument version and upon failure, use the single argument version.

参见 select.add

See select.add

更多推荐

javascript函数在IE 7中不起作用

本文发布于:2023-11-27 21:17:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   函数   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!