我需要单击一个按钮,我想要在选择列表中的两个下拉值之间交换所选选项,以对应于单击的按钮。
这是我到目前为止所拥有的, pERHAPS我的jQUERY有些不对劲,请告知
HTML FirstDropDown:
<li class="zhuanzhangLiCont">
<strong>转出:</strong>
<select name="out" class="select_main" style="width: 225px;">
<option value="0">中心钱包</option>
<option value="132">体育188</option><option value="128">真人娱乐EA</option><option value="134">真人娱乐
</li>
HTML SecondDropDown:
<li class="zhuanzhangLiCont">
<strong>转入:</strong>
<select name="out" class="select_main" style="width: 225px;">
<option value="0>BMW</option>
<option value="52">SPORTS188</option><option value="128">BBIN</option><option value="134">真人娱乐
</li>
HTML按钮:
<li class="exchange"><span>点击交换</span></li>
jQUERY:
function initList(gameCodeList) {
var outList = $("select[name='out']");
var inList = $("select[name='in']");
outList.append("<option value='0'>中心钱包</option>");
for (var i in gameCodeList) {
var game = gameCodeList[i];
var gameString = "<option value='" + game.id + "'>" + game.name + "</option>";
outList.append(gameString);
inList.append(gameString);
}
outList.change(function () {
inList.empty();
if (outList[0].selectedIndex === 0)
inList.append(outList.children().slice(1).clone());
else
inList.append(outList.children().eq(0).clone());
});
$("li.exchange").click(function () {
var outListIndex = outList[0].selectedIndex;
if (outListIndex === 0)
outList[0].selectedIndex = inList[0].selectedIndex + 1;
else {
outList[0].selectedIndex = 0;
}
outList.change();
if (outListIndex !== 0)
inList[0].selectedIndex = outListIndex - 1;
});
}