JqueryアクションSelect
2005 ワード
文章転載自:原文住所
jQueryはSelectで選択したTextとValueを取得する:
jQuery SelectのOptionアイテムの追加/削除:
コンテンツが空です.
1、valueがpxxに設定されている項目選択
多くの場合、selectのカスケード、すなわち、2番目のselectの値は、1番目のselectで選択された値とともに変化します.これはjqueryではとても簡単です.
次のようになります.
jQueryはSelectで選択したTextとValueを取得する:
$("#select_id").change(function(){//code...}); // Select ,
var checkText=$("#select_id").find("option:selected").text(); // Select text
var checkValue=$("#select_id").val(); // Select Value
var checkIndex=$("#select_id ").get(0).selectedIndex; // Select
var maxIndex=$("#select_id option:last").attr("index"); // Select
jQuery SelectのOptionアイテムの追加/削除:
$("#select_id").append(""); // Select Option( )
$("#select_id").prepend(""); // Select Option( )
$("#select_id option:last").remove(); // Select Option( )
$("#select_id option[index='0']").remove(); // Select 0 Option( )
$("#select_id option[value='3']").remove(); // Select Value='3' Optiona
$("#select_id option[text='4']").remove(); // Select Text='4' Optiona
コンテンツが空です.
$("#select_id").empty();
1、valueがpxxに設定されている項目選択
$(".selector").val("pxx");
、textがpxxに設定されている項目選択$(".selector").find("option[text='pxx']").attr("selected",true);
3、現在選択されている項目を取得しているvalue $(".selector").val();
4、現在選択されている項目を取得しているtext $(".selector").find("option:selected").text();
ここではコロンを使用しており、その使い方を把握して逆三を挙げるとコードが簡潔になります.多くの場合、selectのカスケード、すなわち、2番目のselectの値は、1番目のselectで選択された値とともに変化します.これはjqueryではとても簡単です.
次のようになります.
$(".selector1").change(function(){
//
$(".selector2").empty();
// , option
var option = $("