[英]Set element id = javascript function
So I have an issue that I'm not 100% sure on how to solve. 所以我有一个问题,我不是100%肯定如何解决。 Im looping through a list of strings and creating multiple forms, what I want to do is set the id of the elements to the string minus spaces.
我循环遍历字符串列表并创建多个表单,我想要做的是将元素的id设置为字符串减去空格。 I have a javascript function to remove the spaces
我有一个javascript函数来删除空格
function trimWhiteSpaces(name) {
return name.replace(/\s+/g, '');
}
and below is my current code for generating the forms: 以下是我目前生成表单的代码:
@(name: List[String])
... ...
@for(name <- names) {
<td>@name
@form(routes.Application.makeCall()) {
<div id="hiddenForm" style="visibility:hidden">
<input type="text" name="commandID" id="id@name" value="10" />
<input type="text" name="source" id="sourceCall@name" value="source" />
<input type="text" name="destination" id="dest@name" value="@name" />
</div>
<input type="submit" value="Call" id="call@name"/>
}
}
but what I would like to do is: is something like: 但我想做的是:是这样的:
<input type="submit" value="Call" id="call{js:timWhiteSpaces(@name)}"/>
Any help would be appreciated. 任何帮助,将不胜感激。 The other option I have thought that would work would be instead of passing strings pass a new custom objects that has two options.
我认为可行的另一个选项是传递具有两个选项的新自定义对象而不是传递字符串。 But as I'm not an expert at html/javascript i was wondering if there was a way to do it in javascript?
但由于我不是html / javascript的专家,我想知道是否有办法在javascript中做到这一点?
我建议你在服务器端这样做,就像在
id="@(name.replace(" ", ""))"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.