ページ上のテキスト ボックスのペアの値を取得しようとしています。
それらをキャプチャしていますが、重複データを取得しているため、希望どおりに機能していません。
ここに私のHTMLコードがあります:
<div id="links">
<div id="group1">
<input type="text" name="linkTitle" value="Google">
<input type="text" name="linkURL" value="www.google.com">
</div>
<div id="group2">
<input type="text" name="linkTitle" value="Yahoo">
<input type="text" name="linkURL" value="www.Yahoo.com">
</div>
</div>
<div>
<input id="btnSaveLinks" type="button" value="Save">
</div>
そして、ここにJavaScriptがあります:
$("#btnSaveLinks").on('click', function() {
$('#links input[type=text]').each(function () {
var title = $(this).attr("value");
var url = $(this).attr("value");
console.log('title: ' + title);
console.log('url: ' + url);
});
});
タイトル: グーグル
url: グーグル
タイトル: www.google.com
URL: www.google.com
タイトル:ヤフー
url:ヤフー
タイトル: www.yahoo.com
url: www.yahoo.com