2013-05-10 23 views
0

你好(我是一個完整的JS新手,所以請不要欺負) 我試圖通過我的得分變量formID,但我不認爲我得到我的選擇權,任何人都可以告訴我,米做錯了嗎?如何選擇一個Javascript選擇器的參數?

編輯:對不起,每個人,我越來越厭倦。我的問題:我無法正確選擇我的分數變量的值。

JS

function addScore(formId) { 
var show_id = $('#show_id-'+formId).val(); 
var user_id = $('#user_id-'+formId).val(); 
var score = $('input[value="tvshowrating' + formID +'"]').val(); 

HTML

<form id="40"> 
     <div class="your-score"> 
      <div class="">Your Score</div> <div id="flash"></div> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="1" title="1" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="2" title="2" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="3" title="3" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="4" title="4" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="5" title="5" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="6" title="6" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="7" title="7" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="8" title="8" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="9" title="9" /> 
      <input class="hover-star" type="radio" name="tvshowrating40" value="10" title="10" /> 
      <input type="hidden" id="show_id-40" value="40" /> 
      <input type="hidden" id="user_id-40" value="2" /> 
      <span id="hover-test" style="margin:0 0 0 20px;"></span> 
      <input id="submitscore" type="submit" value="Submit scores!" onclick="addScore(40);" /> 
     </div> 
    </form> 
</div> 
+0

您有什麼問題? – SLaks 2013-05-10 22:34:43

+0

提供清楚解釋您的問題的代碼。你已經向我們展示了一個甚至沒有關閉函數大括號的JS代碼片段。 – turnt 2013-05-10 22:35:29

+0

而不是「value =」,你的意思是使用「name =」?以及使用「:checked」選擇器來獲取所選的輸入? – Ian 2013-05-10 22:35:59

回答

3

你被選擇<input>秒。您可能需要input[name=...

+0

的每個名稱應該不同... – 2013-05-10 22:40:54

+0

名稱不需要不同,只需使用「:checked」選擇器來查找選中哪個單選按鈕 – Ian 2013-05-10 22:42:54

相關問題