1

リンク、属性href = ""、テキストリンクでマークされた値を取得するにはどうすればよいですか。英語をお詫びします。ありがとうございました。

<ul id="list-item">
<li><input type="checkbox" checked="checked" /><a href="http://localhost/">Item 1</a></li>
<li><input type="checkbox" /><a href="http://localhost/">Item 2</a></li>
<li><input type="checkbox" /><a href="http://localhost/">Item 3</a></li>
<li><input type="checkbox" /><a href="http://localhost/">Item 4</a></li>
<input type="button" id="save" value="Save"/>

4

3 に答える 3

1

これを試して:

$('#list-item input[type="checkbox"]:checked').next('a').attr('href');

イベントを使用してchange、アンカーのテキストとリンクをマッピングできます。次のことを試してください。

var anchors = [];
$('#list-item input').change(function(){
   var anchors = $(this).closest('ul').find('input:checked').siblings('a').map(function(){
                    return $(this).text() + ": " +this.href
               }).get()    
})

デモ

于 2012-08-15T11:39:00.857 に答える
1

あなたはこれを達成しようとしていると思います:

編集:

$('#list-item input[checked=checked]').each(function(){
    alert($(this).next('a').text() + ': ' + $(this).next('a').attr('href') )
}) 

デモを見る

于 2012-08-15T11:51:20.793 に答える
1

メソッドを使用してfind、要素の下にある要素の値を取得できます。次に、jqueryeachメソッドを使用してコレクションの値を取得します。

このようなもの。

function getAnchorValues(){
    var checklist = $('#list-item').find($('input[type="checked"]:checked');
    $.each(checklist, function(index, val){
        alert index + ' : ' +  val;
    });
}
于 2012-08-15T11:52:50.543 に答える