问题描述
我有一个jsp.使用jquery.load多次加载该jsp.我在jquery中有一些代码
I have a jsp. This jsp is loaded several times using jquery.load. I have some codes in jquery
<input type="radio" name="rating" value="1" class="rateCls star"/>
<input type="radio" name="rating" value="2" class="rateCls star" />
<input type="radio" name="rating" value="3" class="rateCls star"/>
<input type="radio" name="rating" value="4" class="rateCls star"/>
<input type="radio" name="rating" value="5" class="rateCls star"/>
我希望每次加载时都更改输入广播的名称.就像第一次加载时,名称可能会说"rating-0",第二次加载时,名称应更改为"rating-1",依此类推.我想创建全局变量并像这样增加它,但是它不起作用.
I want the name of input radio to be changed each time it loads. Like for the first time it loads the name may be say "rating-0" for the second time it loads the name should be changed to "rating-1" and so on.I think of creating global variable and increment it something like this but it is not working.
<%!int index=1;%>
<index+=1;>
<input type="radio" name="rating+${index}" value="1" class="rateCls star"/>
<input type="radio" name="rating" value="2" class="rateCls star" />
<input type="radio" name="rating" value="3" class="rateCls star"/>
<input type="radio" name="rating" value="4" class="rateCls star"/>
<input type="radio" name="rating" value="5" class="rateCls star"/>
我不知道如何在jsp中将jstl全局变量用作id.
I do not know how to use jstl global variable as id in jsp.
推荐答案
使用form
元素.相同name
的单选按钮是按表单链接的,因此只要这些评级组的每个实例都包装在其自己的form
中,它们就不会发生串扰,因此您无需为每个单选按钮组是唯一的name
.
Use a form
element. Radio buttons of the same name
are linked on a per-form basis so as long as each instance of these rating group is wrapped in its own form
they wont cross-talk and so you'll avoid the need to give each group of radio buttons a unique name
.
这是一个示例jsFiddle ,它使用了来自.这两种形式是完全相同的,但收音机不会发生冲突.
Here's an example jsFiddle using the HTML markup from your other question. The 2 forms are the exactly the same but the radios don't conflict.
这篇关于在JSP中使用jstl全局变量作为id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!