ホームページ  >  記事  >  ウェブフロントエンド  >  jQueryはSelectで選択されたTextとValueを取得します。

jQueryはSelectで選択されたTextとValueを取得します。

巴扎黑
巴扎黑オリジナル
2017-06-29 10:09:001180ブラウズ

jQuery は Select で選択された Text と Value を取得します:
構文の説明:
1. $("#select_id").change(function(){//code...}); // event を追加します。いずれかの項目が選択されるとトリガーされる Select
2. var checkText=$("#select_id").find("option:selected").text(); //Select で選択されたテキストを取得します
3. =$( "#select_id").val(); // Select
の値を取得します。 var checkIndex=$("#select_id ").get(0).selectedIndex; // indexの値を取得します。 Select
5 . var maxIndex=$("#select_id option:last").attr("index"); //Select の最大インデックス値を取得します
jQuery は Select の Text と Value を設定します:
構文説明:
1 . $(" #select_id ").get(0).selectedIndex=1; // 項目を選択するには、Select インデックス値を 1 に設定します。 $("#select_id ").val(4); Select Value を 4 に設定します。項目が選択されます
3. $("#select_id option[text='jQuery']").attr("selected", true); //Select の Text 値を、選択された項目に設定します。 jQuery

jQuery 選択オプション項目:

構文説明:
1. $("#select_id").append("");選択するオプション (ドロップダウン項目)
2. $("#select_id").prepend("");最初の位置) for Select
3 . $("#select_id option:last").remove(); //Select 内の最大のインデックス値を持つオプションを削除します
4. index='0']").remove( ); //Select
5のインデックス値0のオプション(最初の1つ)を削除 $("#select_id option[value='3']").remove() ; //Select 'Option
のValue='3を削除します。 $("#select_id option[text='4']").remove(); //Select 'Option
のText='4'を削除​​します。 http://www.cnblogs.com/ SAL2928/archive/2008/10/28/1321285.html

jquery ラジオ値、チェックボックス値、選択値、ラジオ選択、チェックボックス選択、選択選択、および関連

値を取得するラジオで選択された一連の項目の

var item = $('input[name=items][checked]').val();
select で選択された項目のテキストを取得します
var item = $("select[name =items] option[selected]") .text();
選択ドロップダウン ボックスの 2 番目の要素は現在選択されている値です
$('#select_id')[0].selectedIndex = 1;
2 番目の要素ラジオ選択グループの現在選択されている値です
$ ('input[name=items]').get(1).checked = true;
値の取得:
テキスト ボックス、テキスト エリア: $("#txt" ).attr("value");
複数選択ボックスのチェックボックス: $("#checkbox_id").attr("value");
ラジオ選択グループラジオ: $("input[type=radio][checked]") .val();
ドロップダウンボックス選択: $(' #sel').val();
コントロールフォーム要素:
テキストボックス、テキストエリア: $("#txt").attr("value", '');//内容をクリア
$("#txt" ).attr("value",'11');//内容を埋める
複数選択ボックスチェックボックス: $("#chk1").attr( "checked",'');//チェックを外す
$(" #chk2").attr("checked",true);//チェックを入れる
if($("#chk1").attr('checked')= =unknown) //チェックされているかどうかを判断します
ラジオグループ radio: $("input[type=radio]").attr("checked",'2');//value=2 の項目を設定します現在選択されている項目
ドロップダウン ボックス select: $("#sel"). attr("value",'-sel3');//value=-sel3 の項目を現在選択されている項目として設定します
$("< ;option value='1'>1111").appendTo("#sel")//ドロップダウンボックスのオプションを追加します
$("#sel").empty();//ドロップダウンボックスをクリアします

-- ----------------------- ----------------------------------------------------- -------------------------

// オプションをトラバースし、オプションを追加および削除します

function changeShipMethod(shipping){

var len = $ ("select[name=ISHIPTYPE] オプション").length
if(shipping.value != "CA"){
$(" select[name=ISHIPTYPE] オプション").each(function(){
if($ (this).val() == 111){
$(this).remove();
}
});
} else{
$("

$(#testSelect option:selected').text();
または $("#testSelect").find('option:selected').text();
または $("#testSelect").val( );
///////////////////////////////////////////// /// ////////////////////
記憶力が悪い場合は、保存できます:
1、ドロップダウン ボックス:

var cc1 = $ (".formc select[name='country '] option[selected]").text(); //ドロップダウン メニューで選択された項目のテキストを取得します (中央のスペースに注意してください)
var cc2 = $('.formc select[name="country"]') .val() //ドロップダウンメニューで選択した項目の値を取得します
var cc3 = $('.formc select[name= "country"]').attr("id"); //ドロップダウン メニューで選択されている項目の ID 属性値を取得します
$("#select").empty();//ドロップダウン ボックスをクリアします//$("#select").html('');
$("").appendTo("#select")//オプションを追加しますドロップダウン ボックスの

ちょっとした説明:
1.select[name='country'] option[selected] は、name 属性を持つことを意味し、
属性値は、selected 属性を持つオプション要素です。 select element of 'country'

2, radio button:
$("input[@type=radio][@checked]").val() ; //ラジオボタンの選択された項目の値を取得します(間にスペースがないことに注意してください)
$("input[@type=radio][@value=2]").attr("checked",'checked'); / /ラジオボタンの値を 2 に設定します。 (真ん中にスペースがないことに注意してください)

3,checkbox:
$("input[@type=checkbox][@checked]").val() ;チェックボックスで最初に選択された項目の値
$("input[@type=checkbox][@checked]").each(function() { //チェックボックスには通常複数の選択項目があるため、出力することができますループ内
alert($(this).val());
});

$("#chk1").attr("checked",'');//Unchecked
$ ("#chk2" ).attr("checked",true);//Tick
if($("#chk1").attr('checked')==unknown){} //チェックされているかどうかを判断します

もちろん jquery のselector は強力なメソッドがたくさんあります。


< ;script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#selectTest").change(function()
{
//alert ("Hello");
//alert($("#selectTest").attr("name"));
//$("a").attr("href","xx.html");
//window.location. href="xx.html";
//alert($("#selectTest").val());
alert($("#selectTest オプション[@selected]").text ());
$( "#selectTest").attr("value", "2");

});
});



jquery ラジオ値、チェックボックス値、選択値、選択されたラジオ、選択されたチェックボックス、選択が選択されており、ラジオで選択された項目のセットの値の取得に関連しています
var item = $('input[@name=items][@checked]').val();
選択された項目のテキストを取得しますselect
var item = $("select[@name=items] option[@selected]").text();
select ドロップダウン ボックスの 2 番目の要素は、現在選択されている値です
$('#select_id' )[0].selectedIndex = 1;
ラジオラジオグループの 2 番目の要素は現在選択されている値です
$('input[@name=items]').get(1).checked = true;
値を取得:
テキストボックス、テキストエリア:$("#txt").attr("value");
複数選択ボックスチェックボックス:$("#checkbox_id").attr("value");
ラジオグループ radio:$( "input[@type =radio][@checked]").val();
ドロップダウンボックス選択: $('#sel').val();
コントロールフォーム要素:
テキストボックス、テキストエリア: $("#txt") .attr("value",'');//コンテンツをクリア
$("#txt").attr("value",'11');//コンテンツを埋める
チェックボックス: $("#chk1 ").attr("checked",'');//未チェック
$("#chk2").attr("checked",true);//チェックあり
if($("# chk1") .attr('checked')==unknown) //チェックされているかどうかを判定
ラジオグループ radio: $("input[@type=radio]").attr("checked",'2') ;// value=2 の項目を現在選択されている項目として設定します
ドロップダウン ボックス select: $("#sel").attr("value",'-sel3');// value= の項目を設定します現在選択されている項目として -sel3
$ ("2222 $("#sel").empty(); // ドロップダウンボックスをクリアします

ラジオで選択された項目のセットの値を取得します
var item = $ ('input[@name=items][@checked]').val ();
selectで選択した項目のテキストを取得
var item = $("select[@name=items] option[@selected]" ).text();
選択ドロップダウン ボックスの 2 番目の要素は、現在選択されている値です
$('#select_id')[0].selectedIndex = 1;
ラジオラジオ選択グループの 2 番目の要素は、現在選択されている値
$('input[@name=items]').get(1).checked = true;
値の取得:
テキストボックス、テキストエリア: $("#txt").attr("value" );
複数選択ボックスのチェックボックス: $("#checkbox_id").attr("value");
ラジオ選択グループのラジオ: $("input[@type=radio][@checked]").val();
ドロップダウンボックス選択: $('#sel').val();
コントロールフォーム要素:
テキストボックス、テキストエリア: $("#txt").attr("value",'');/ /内容をクリア
$("#txt").attr("value",'11');// 内容を入力
複数選択ボックスチェックボックス: $("#chk1").attr("checked", '');//
$("#chk2").attr("checked",true);// チェックを外す
if($("#chk1").attr('checked')==unknown) / /チェックされているかを判定
ラジオグループ radio: $("input[@type=radio]"). attr("checked",'2');//現在選択されている項目としてvalue=2の項目を設定します
ドロップダウンボックス select: $("#sel").attr("value",'-sel3');// value=-sel3 の項目を現在選択されている項目として設定します
$("").appendTo( "#sel")//ドロップダウンボックスのオプションを追加します
$( "#sel").empty();//ドロップダウンボックスをクリアします

以上がjQueryはSelectで選択されたTextとValueを取得します。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。