[jquery获取select的值]jQuery实例select双向选择列表实例教程

更新时间:2019-08-10    来源:jquery    手机版     字体:

【www.bbyears.com--jquery】

提示:您可以先修改部分代码再运行


<br /> New Document<br />




<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js">
</script>






























<script>
$(function() {
$("#sel_left,#sel_right").bind("change", checkBtn);
$("#btn_1,#btn_2,#btn_3,#btn_4").bind("click", clickBtn);
checkBtn();
});

function checkBtn() {
jQuery("#sel_left>option").length > 0 ? jQuery("#btn_1").removeAttr("disabled") : jQuery("#btn_1").attr("disabled", "disabled");
jQuery("#sel_left option:selected").length > 0 ? jQuery("#btn_2").removeAttr("disabled") : jQuery("#btn_2").attr("disabled", "disabled");
jQuery("#sel_right option:selected").length > 0 ? jQuery("#btn_3").removeAttr("disabled") : jQuery("#btn_3").attr("disabled", "disabled");
jQuery("#sel_right>option").length > 0 ? jQuery("#btn_4").removeAttr("disabled") : jQuery("#btn_4").attr("disabled", "disabled");
}

function clickBtn(e) {
if ("btn_1" == e.target.id) {
jQuery("#sel_left>option").appendTo("#sel_right");
} else if ("btn_2" == e.target.id) {
jQuery("#sel_left option:selected").appendTo("#sel_right");
} else if ("btn_3" == e.target.id) {
jQuery("#sel_right option:selected").appendTo("#sel_left");
} else if ("btn_4" == e.target.id) {
jQuery("#sel_right>option").appendTo("#sel_left");
}
checkBtn();
}
</script>

提示:您可以先修改部分代码再运行

本文来源:http://www.bbyears.com/wangyezhizuo/61321.html

热门标签

更多>>

本类排行