-1
我想要使用jQuery獲取HTML表單的值。
在我的表格中是兩個div info1和info2,在jquery中我有兩個變量存儲和store2
info1的值保存在變量存儲中,info2的值保存在store2中。
但是,這是代碼中的一些錯誤,由於這個原因,這是不運行。請參閱下面的代碼。
這裏是代碼:使用jquery從HTML表單中獲取值
<form>
<div id="info1">
<input type="text" />
<input type="text" />
<input type="text" />
</div>
<div id="info2">
<input type="text" />
<input type="text" />
</div>
<input type="button" id="btn" value="click" />
</form>
JQUERY:
$(document).on('click','#btn',function(){
var store = [];
var store2 = [];
$('#info1 :input[type="text"]').map(function(){
var values = $(this).val();
store.push({values:values});
});
$('#info2 :input[type="text"]').map(function(){
var values = $(this).val();
store2.push({values:values});
});
});
此代碼不能正常工作。我認爲錯誤在這裏$('#info1 :input[type="text"]')
。
請解決這個問題。
Thankx。
你嘗試_ $( '#INFO1輸入[類型= 「文本」]')_? (沒有「:」) – 2014-10-02 10:59:18
沒有人在這裏解決this_。 SO不是由_freelancers_編寫的,它可以爲你編寫代碼並且免費。 – melancia 2014-10-02 10:59:48
除了不使用'store2'你的代碼似乎工作得很好:http://jsfiddle.net/TrueBlueAussie/u6c4wojb/2/。你有什麼問題? – 2014-10-02 11:03:11