我正在使用jQuery raty创建一个个人网站。我有一个表单,raty为每组星星生成以下内容
<input type="hidden" name="score" value="5"> 其中value包含我想要获取的值。
我有10个字段,每个5星,我想获得所有10个评价与PHP/POST插入到数据库中。
对于输入具有相同名称的事实,我该怎么办?我知道如果它是name="score[]“,我可以访问数组中的评级,但我不认为我可以更改raty分配给输入的名称
发布于 2013-11-13 08:39:01
如果你不能改变雷蒂的名字,这应该会帮助你
HTML
<input type="hidden" name="score" value="5">
<input type="hidden" name="score" value="5">
<input type="hidden" name="score" value="5"> jQuery
$(document).ready(){
var score;
$('input[name="score"]').each(function(index) {
//YOUR LOGIC
//IE: score = $(this).val(); console.log(score);
//IE: POPULATE hidden submit form or store for AJAX call
});
});但是,如果您可以添加一个类,最好这样做
HTML
<input type="hidden" class='score' name="score" value="5">
<input type="hidden" class='score' name="score" value="5">
<input type="hidden" class='score' name="score" value="5"> jQuery
$(document).ready(){
var score;
$('.score').each(function(index) {
//YOUR LOGIC
//IE: score = $(this).val(); console.log(score);
});
});或者使用父div id和child()方法
https://stackoverflow.com/questions/19942928
复制相似问题