gpt4 book ai didi

javascript - 如何选择 Javascript 选择器的参数?

转载 作者:行者123 更新时间:2023-11-28 12:00:42 26 4
gpt4 key购买 nike

大家好(我是一个完全的 JS 新手,所以请不要欺负我)我试图在我的分数变量中传递 formID,但我认为我的选择器不正确,有人能告诉我我做错了什么吗?

编辑:对不起大家,我累了。我的问题:我无法正确选择我的分数变量的值。

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>

最佳答案

您可能想要检查的值:

$('input[name="tvshowrating' + formID +'"]:checked').val()
<小时/>

这是另一个可以回答您的问题的问题: Get Value of Radio button group或者 How can I know which radio button is selected via jQuery?

关于javascript - 如何选择 Javascript 选择器的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16491723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com