質問

タイトルに言ったように 例えばます:

<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>

どのように私は、テキストを取得することができます。ユーザー1

役に立ちましたか?

解決

<ストライキ> $( '入力:ラジオ:確認')。兄弟( 'ラベル:最初の')。htmlの()

<時間>

UPDATE:

としては、以前のセレクタは、常に最初のラベルを選択しますコメント欄でビクターが指摘しました。 の機能が動作するはずます:

$('input:radio:checked').next('label:first').html()

他のヒント

これはどう?

var forLabel = $('input:radio:checked').attr("id");
$("label[for='" + forLabel + "']").text();

使用.next();

$("input:radio:checked").next().text();

私にとってはこの作品(私はjQueryのモバイルを使用していたよ):

var value = $(":radio[name=location]:checked").val();
var text = $(":radio[name=location]:checked").prev("label").text();

このためDOMます:

<div id="locations" data-role="controlgroup" class="ui-controlgroup ui-controlgroup-vertical ui-corner-all">
   <div class="ui-controlgroup-controls ">
      <div class="ui-radio">
         <label for="location0" class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-radio-off ui-first-child">1439</label>
         <input type="radio" name="location" id="location0" value="1439">
      </div>
      <div class="ui-radio">
         <label for="location1" class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-radio-off ui-last-child">1440</label>
         <input type="radio" name="location" id="location1" value="1440">
      </div>
   </div>
</div>

次は何隣接セレクタの使用方法について、+ の?

$('input:radio:checked + label').text();

ここでの ワーキングデモ

です
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top