Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在一个表单中有多个jquery raty时,如何命名输入?_Javascript_Jquery_Forms - Fatal编程技术网

Javascript 在一个表单中有多个jquery raty时,如何命名输入?

Javascript 在一个表单中有多个jquery raty时,如何命名输入?,javascript,jquery,forms,Javascript,Jquery,Forms,我正在使用jquery raty插件制作一个具有星级的表单 插件为每个星级输入生成一个隐藏字段,如下所示: <input id="question8-score" type="hidden" name="score"> <input id="question6-score" type="hidden" name="score"> <input id="question5-score" type="hidden" name="score"> 问题是,当我验

我正在使用jquery raty插件制作一个具有星级的表单

插件为每个星级输入生成一个隐藏字段,如下所示:

<input id="question8-score" type="hidden" name="score">
<input id="question6-score" type="hidden" name="score">
<input id="question5-score" type="hidden" name="score">

问题是,当我验证表单时(我使用codeigniter),它只会与3个同名输入混淆。因此,我想制作一个脚本,可以执行以下操作:

对于name=“score”的每个输入,将id属性值作为name属性值

我认为使用jQuery可能是可行的,但我不知道如何做到这一点。有人能帮我吗?谢谢

$("input[name=score]").each(function () { 
    this.name = this.id;
});
编辑选择器

$('input[name=score]').each(function(){
    $(this).attr("name", $(this).attr("id"));
});
编辑了选择器

为什么不使用`name=“score[]”-php似乎喜欢这些为什么不使用`name=“score[]”-php似乎喜欢这些设置:)以及什么选择器只有'inputs with name=“score”'?太好了:)以及什么选择器只有'inputs with name=“score'?
$('input[name=score]').each(function(){
    $(this).attr("name", $(this).attr("id"));
});