将 JSP 变量输出到 JavaScript 代码段中
Output JSP variable into JavaScript snippet
我的循环中有一个varStatus
,我想将其发送到js中的函数。
这是我所拥有的:
onkeyup="clickableButton(this.value, ${newCommentStatus.index})"
但${newCommentStatus.index}
是不确定的。我如何发送此值?
提前致谢
编辑
<c:forEach items="${threadviewModel.emailToShowList}" var="row" varStatus="status">
<form:form modelAttribute="commentFieldModel">
<span class="commentInput"><form:input id="commentInput" type="text" path="commentText" size="90" value=" " onkeyup="clickableButton(this.value, ${status.index})"/></span>
<div><input disabled="true" type="submit" id="save-${status.index}" name="_eventId_addComment" value="Save"/></div>
</div>
</form:form>
脚本代码
function clickableButton(text, id) {
if (text.length > 0)
document.getElementById("save-" + id).disabled = false;
else
document.getElementById("save-" + id).disabled = true;
}
;
您的<c:forEach>
调用变量"status",而不是"newCommentStatus"。
事件处理程序如下所示:
... onkeyup="clickableButton(this.value, ${status.index})" ...
另外,你可以清理你的JavaScript:
function clickableButton(text, id) {
document.getElementById("save-" + id).disabled = text.length <= 0;
}
试试这个方法
onkeyup="clickableButton(this.value, '${newCommentStatus.index}')"
${newCommentStatus.index} 不是标准的 JavaScript。
我怀疑您正在使用JQuery或类似的东西:尝试${newCommentStatus}.index
这将适用于一些假设。
相关文章:
- 如何在读取XLS/XLSX本地文件时,使用IE的javascript代码启用未标记为安全的ActiveX控件
- 面向对象的Javascript代码在IE7中不起作用
- 通过命令行/批处理文件打开页面时,将javascript代码注入Google Chrome
- JavaScript代码问题:我正在将对象转换为数组
- Javascript阻止其他Javascript代码
- JavaScript代码未正确检查ajax请求
- 如何调试Javascript代码或函数
- 为什么我在这个javaScript代码中使用NaN
- 将javascript代码转换为jquery代码时出错
- 如何从Objective-C代码中调用javascript代码
- 有什么工具可以轻松读取javascript代码吗
- 这个javascript代码是如何编写的
- 如何解密此javascript代码
- SIMPLE Javascript代码,用于显示谷歌电子表格中单个字段的数据
- HTML标记,包含带引号的JavaScript代码中的引号
- 如何在Win8Metro应用程序的Javascript代码中捕获自己的C#事件
- addEventListener的Javascript代码不工作!?(单击时打开放大的img)
- JavaScript代码无法在表单上呈现部分
- 以下 JavaScript 代码与 Facebook 相关
- 使用解析为javascript源的.php,如何使用条件语句将javascript代码封装在php括号之间