Javascript 在一个表单中有多个jquery raty时,如何命名输入?
我正在使用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"> 问题是,当我验
<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"));
});