1
所以我有一个问题,我不能100%确定如何解决。 Im遍历字符串列表并创建多个表单,我想要做的是将元素的id设置为字符串减空格。 我有一个JavaScript函数把空格去掉设置元素id = javascript函数
function trimWhiteSpaces(name) {
return name.replace(/\s+/g, '');
}
以下是我当前的代码生成的形式:
@(name: List[String])
...
@for(name <- names) {
<td>@name
@form(routes.Application.makeCall()) {
<div id="hiddenForm" style="visibility:hidden">
<input type="text" name="commandID" id="[email protected]" value="10" />
<input type="text" name="source" id="[email protected]" value="source" />
<input type="text" name="destination" id="[email protected]" value="@name" />
</div>
<input type="submit" value="Call" id="[email protected]"/>
}
}
,但我想什么要做的是: 就像这样:
<input type="submit" value="Call" id="call{js:timWhiteSpaces(@name)}"/>
任何帮助,将不胜感激。 我认为可以工作的另一种选择将不是传递字符串而是传递具有两个选项的新自定义对象。但因为我不是HTML/javascript的专家,我想知道是否有一种方法可以在JavaScript中执行此操作?
酷非常感谢你。 我是abloe使用以下,它的工作: – user1434177