繁体   English   中英

取消(重置html)按钮不起作用

[英]cancel( reset the html ) button is not working

我是html,javascript和CSS的新手。 我不知道为什么,但是我的“取消”按钮根本不起作用。

<!DOCTYPE html>

<html>
<head>
<!-- set the page title and link with java script and css files -->
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="hw4.css">
<script src="hw4.js"></script>
</head>
<body>
<section>
    <table>
        <tr>
            <td class="first">Post to</td>

            <!-- create two post to buttons -->
            <td class="second"><input id="entire" type="radio" name="post"
                value="entire" checked>Entire Class <input type="radio"
                id="individual" name="post" value="individual">Individual
                Student(s)/instructor(s)</td>
        </tr>

        <tr>
            <td class="first">Select Folder(s)</td>
            <td class="second">
                <!-- create six homework checkboxes -->
                <div class="hw">
                    <input id="hw1" type="checkbox"><label for="hw1">hw1</label>
                    <input id="hw2" type="checkbox"><label for="hw2">hw2</label>
                    <input id="hw3" type="checkbox"><label for="hw3">hw3</label>
                    <input id="hw4" type="checkbox"><label for="hw4">hw4</label>
                    <input id="hw5" type="checkbox"><label for="hw5">hw5</label>
                    <input id="hw6" type="checkbox"><label for="hw6">hw6</label>
                </div>
            </td>
        </tr>

        <tr>
            <td class="first">Summary
                <div style="font: 10px Arial">(100 charactors or less)</div>
            </td>

                <td class="second"><input id="summary" type="text" size="25"
                value="Enter a one line summary...!" onclick="this.value='';"></td>
        </tr>

        <tr>
            <td class="first">Details</td>

            <!-- create detail text area. -->
            <td class="second"><textarea id="details" name="textarea"
                    rows="10" cols="50" wrap='off'></textarea></td>
        </tr>

        <tr>
            <td class="first">Posting Options</td>

            <!-- create two option check boxes -->
            <td><input id="option1" type="checkbox"> Make this an
                announcement (note appears on the course page)</br> <input id="option2"
                type="checkbox"> Send email notifications immediately
                (bypassing student's email preferences, if neccesory)</td>
        </tr>

        <tr>
            <td></td>

            <td>
                <input id="post" type="submit" value="Post My Note!" onClick="check()">
                <input id="cancel" type="reset" value="Cancel" />
            </td>
    </table>
</section>

</body>

</html>

当我运行此代码时,一切正常,但“取消”按钮不起作用。 我想我做错了,因为它像30分钟前一样起作用,但是现在它根本不起作用,我无法弄清楚哪里出了问题...!

您没有form标签。 重置按钮清除表单内的值。

2个解决方案:

  • 将输入元素包装在<form><!-- elements here --></form>
  • 编写一段脚本,以在单击清除按钮时清除要清除的元素。

尝试这个:

重置按钮仅适用于表单标签。 因此,请如我在演示中所示,在您的代码中添加表单标签。

 <script src="hw4.js"></script> </head> <body> <section> <table> <form> <tr> <td class="first">Post to</td> <!-- create two post to buttons --> <td class="second"><input id="entire" type="radio" name="post" value="entire" checked>Entire Class <input type="radio" id="individual" name="post" value="individual">Individual Student(s)/instructor(s)</td> </tr> <tr> <td class="first">Select Folder(s)</td> <td class="second"> <!-- create six homework checkboxes --> <div class="hw"> <input id="hw1" type="checkbox"><label for="hw1">hw1</label> <input id="hw2" type="checkbox"><label for="hw2">hw2</label> <input id="hw3" type="checkbox"><label for="hw3">hw3</label> <input id="hw4" type="checkbox"><label for="hw4">hw4</label> <input id="hw5" type="checkbox"><label for="hw5">hw5</label> <input id="hw6" type="checkbox"><label for="hw6">hw6</label> </div> </td> </tr> <tr> <td class="first">Summary <div style="font: 10px Arial">(100 charactors or less)</div> </td> <td class="second"><input id="summary" type="text" size="25" value="Enter a one line summary...!" onclick="this.value='';"></td> </tr> <tr> <td class="first">Details</td> <!-- create detail text area. --> <td class="second"><textarea id="details" name="textarea" rows="10" cols="50" wrap='off'></textarea></td> </tr> <tr> <td class="first">Posting Options</td> <!-- create two option check boxes --> <td><input id="option1" type="checkbox"> Make this an announcement (note appears on the course page)</br> <input id="option2" type="checkbox"> Send email notifications immediately (bypassing student's email preferences, if neccesory)</td> </tr> <tr> <td></td> <td> <input id="post" type="submit" value="Post My Note!" onClick="check()"> <input id="cancel" type="reset" value="Cancel" /> </td> </form> </table> </section> </body> </html> 

请享用 :)

暂无
暂无

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

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