简体   繁体   English

Javascript onload事件未调用

[英]Javascript onload event not invoking

I am working on a simple application whereby users can select snowboarding programmes. 我正在开发一个简单的应用程序,用户可以在其中选择滑雪板程序。 They can only select a maximum of 3 programmes thus, the program checks a collection that stores the programmes and if it contains > 3 entries, then it should disable all the buttons available to the user. 他们最多只能选择3个程序,因此,程序将检查存储程序的集合,并且如果包含> 3个条目,则应禁用用户可用的所有按钮。 However the function doesn't seem like it's being invoked.I have tried with different event triggers such as onclick etc but to no avail. 但是该函数似乎没有被调用,我尝试过使用不同的事件触发器,例如onclick等,但无济于事。 Any help is appreciated. 任何帮助表示赞赏。

时间表检视

Javascript Function: JavaScript函数:

<script type="text/javascript">
   function restrictSelection(t) {

        var selectedButton = document.getElementById(t);
        var selectedLessonSize = document.getElementById("selectedLessonSize");
        if (selectedLessonSize.value > 3) { 
            alert("more than 3");
             selectedButton.disabled = true;  
         } else {
             selectedButton.disabled = false;
             alert("less than 3");
         }  
 }  

</script>

JSP ForEach Loop (iterates through a collection and displays available programmes): JSP ForEach循环(遍历一个集合并显示可用的程序):

<c:forEach var="entry" items="${lessonTimetable.lessons}">

    <form method="POST" action="chooseLesson">
        <tr>
            <td><c:out value="${entry.key}"/></td>
            <td><c:out value="${entry.value.description}"/></td>
            <td><c:out value="${entry.value.date}"/></td>
            <td><c:out value="${entry.value.startTime}"/></td>
            <td><c:out value="${entry.value.endTime}"/></td>
            <td><c:out value="${entry.value.level}"/></td>
            <td><input type="hidden" name="lessonid" value="${entry.key}"/>
                <input type="hidden" id="selectedLessonSize" value="${lessonSelection.numChosen}"/>
                <input id="button${entry.key}" type="submit" value="select lesson" disabled="true" onload="restrictSelection(this)"/>
            </td>
        </tr>
    </form>
</c:forEach>

尝试将<input id="button${entry.key}" type="submit" .....更改为<button id="button${entry.key}" onclick="restrictSelection(this.id)">.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM