【发布时间】:2011-08-17 01:28:27
【问题描述】:
好的,所以我有这段代码,过去可以正常工作。我最近将我的 jQuery 从 1.4.4 升级到 1.5.2,显然这已经停止工作了。但是,我已经尝试了 1.4.4 的代码。和 1.3.2,它也不会在那里工作。
这确实有效。我不知道为什么不是。有什么帮助吗?
编辑:start 和 end 是参数,带有 select 元素 ID 的文本。
var selectedIndex = document.getElementById(start).selectedIndex; // get the selected index from the correct select box
if (selectedIndex != -1) { // if something is selected, do the following:
var selectedElement = document.getElementById(start).options[selectedIndex]; // get the element that's selected
if (selectedIndex == (document.getElementById(start).options.length - 1) && selectedIndex != 0) {
selectedIndex--; // if we're at the bottom of the list, set our selectedIndex variable to the one right before it
}
$("#" + start).remove(selectedElement); // remove the selected element from the start side
$("#" + end).append(selectedElement); // and add it to the end of the ending side
}
这是我要移动的选项的示例。<option sortable="yes" datatype="string" value="foo" type="arbitrary">Foo</option>
我遇到的问题显然是 jQuery 本身 - 使用完整版本,expr.replace is not a function
[Break On This Error] expr = expr.replace( /\=\s*([^'"]])\s]/g, "='$1']" ); [jquery-latest.debug.js, line 4540]
当我点击代码的$.remove 部分时发生错误。
谢谢。
【问题讨论】:
-
为什么说这行不通。我的意思是,错误是什么?
-
HTML 是动态生成的。使用选项和错误更新了 OP。真不敢相信我忘了提到问题到底是什么。
标签: jquery