在JSP中使用jstl全局变量作为id [英] use jstl global variable as id in JSP

查看:369
本文介绍了在JSP中使用jstl全局变量作为id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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.

具有相同名称属性值的单选按钮位于同一单选按钮组"中;一次只能选择一个组中的一个单选按钮.
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/Input

Radio buttons that have the same value for the name attribute are in the same "radio button group"; only one radio button in a group can be selected at one time.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input

这是一个示例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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆