2016-03-27 68 views
1

也許簡單的問題,而是如何在jQuery中寫道輸入的名稱:輸入名稱jQuery中

HTML

<input type="hidden" name="user[profile_attributes][birthdate(3i)]" value="3"> 

JQUERY:

這似乎並不工作或bug是別的地方:

jQuery('input[name="user[profile_attributes][birthdate(3i)"]') 
+0

你缺少一個']'在選擇 –

+0

錯字的末尾: 'jQuery的('輸入[名稱=「用戶[ profile_attributes] [birthdate(3i)「]')'<---'」]'應該是']「'。 https://jsfiddle.net/2sgetdpL/(你當前的querySelector正在尋找'input [name =「user [profile_attributes] [birthdate(3i)''而不是'input [name =」user [profile_attributes] [birthdate(3i) ]') – briosheje

+0

感謝typo和hide()+ diable,真的不要發送var形式 – Wordica

回答

0

您的Ĵ查詢選擇一個錯字,應該是:

jQuery('input[name="user[profile_attributes][birthdate(3i)]"]') 
0
  1. 您也可以在不同的attribut

    <input type="hidden" name="user[profile_attributes][birthdate(3i)]" value="3"> 
    

保存數據此

<input type="hideen" name="VALUE" profile="VALUE" birthday="VALUE"> 
  • 然後,隨着jquery,提取值爲:

    var name = $(this).attr(name);

    var profile = $(this).attr(profile);

    var birthday = $(this).attr(birthday);

  • 或者將其保存爲使用Ajax的對象:

    var data = {name:$(this).attr(name), profile:$(this).attr(profile), birthday:$(this).attr(birthday)};