下拉框的value值和text值的操作方法
1、jquery獲取當前選中select的text值
var test=$("#id").find("option:selected").text();
2、jquery獲取當前選中select的value值
var test=$("#id").val();
3、jquery獲取當前選中select的索引值
var index=$("#id ").get(0).selectedIndex;
4、jquery設置索引值爲1的項爲當前選中項
$("#id ").get(0).selectedIndex=1;
5、jquery設置value值2的項爲當前選中項
$("#id").val(2);
6、jquery設置text值爲"測試"的項爲當前選中項
$("#id option[text='測試']").attr("selected",true);
7、爲指定select下拉框追加一個option(追加到在末尾)
$("#id").append(""+i+"");
8、爲制定select下拉框插入一個option(插入到第一個位置)
$("#id").prepend("請選擇");
9、jquery刪除select下拉框的最後一個option
$("#id option:last").remove();
var test=$("#id").find("option:selected").text();
2、jquery獲取當前選中select的value值
var test=$("#id").val();
3、jquery獲取當前選中select的索引值
var index=$("#id ").get(0).selectedIndex;
4、jquery設置索引值爲1的項爲當前選中項
$("#id ").get(0).selectedIndex=1;
5、jquery設置value值2的項爲當前選中項
$("#id").val(2);
6、jquery設置text值爲"測試"的項爲當前選中項
$("#id option[text='測試']").attr("selected",true);
7、爲指定select下拉框追加一個option(追加到在末尾)
$("#id").append(""+i+"");
8、爲制定select下拉框插入一個option(插入到第一個位置)
$("#id").prepend("請選擇");
9、jquery刪除select下拉框的最後一個option
$("#id option:last").remove();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.