-1

我的循环中有一个varStatus,我想将它发送到 js 中的一个函数。

这就是我所拥有的:

onkeyup="clickableButton(this.value, ${newCommentStatus.index})"

但是${newCommentStatus.index}是未定义的。我怎么能发送这个值?

提前感谢ins

编辑

    <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>

Javascript代码

function clickableButton(text, id) {
            if (text.length > 0)
                document.getElementById("save-" + id).disabled = false;
            else
                document.getElementById("save-" + id).disabled = true;
        }
        ;
4

3 回答 3

3

<c:forEach>将变量称为“status”,而不是“newCommentStatus”。

事件处理程序如下所示:

... onkeyup="clickableButton(this.value, ${status.index})" ...

此外,您可以清理 JavaScript:

    function clickableButton(text, id) {
        document.getElementById("save-" + id).disabled = text.length <= 0;
    }
于 2012-08-14T14:11:45.060 回答
0

换个方式试试

onkeyup="clickableButton(this.value, '${newCommentStatus.index}')"

于 2012-08-15T05:59:30.033 回答
-1

${newCommentStatus.index} 不是标准的 JavaScript。
我怀疑您使用的是 JQuery 或类似的东西:尝试 ${newCommentStatus}.index
这将适用于一些假设。

于 2012-08-14T14:09:30.533 回答