禁用提交按钮,直到字段有文本?

时间:2014-04-09 18:45:32

标签: html

所以我有一个包含两个字段的表单,其中一个字段需要有信息才能成功显示下一页。如果该字段中包含一些文本,我将如何禁用提交按钮?

这是HTML代码;

    <div id="content">

    <form action="avatarquery.php" method="POST" id="login-form">

        <fieldset>

            <p>
                <label for="login-username">Server Name:</label>
                <input type="text" id="login-username" name="name" class="round full-width-input" autofocus />
            </p>

            <p>
                <label for="login-password">Server IP:</label>
                <input type="text" id="login-password" name="ip" class="round full-width-input" />
            </p>

            <input class="button round blue image-right ic-right-arrow" type="submit" id="register" />


        </fieldset>

        <br/><div class="information-box round">Please Note: Some servers may not work due to their Configs not having Query Enabled.</div>

    </form>

1 个答案:

答案 0 :(得分:2)

如果必须使用HTML完成,那么在HTML5中,您可以使用

<input type="text" required />

否则,在JavaScript中,您可以尝试将属性设置为输入按钮。

在值为“”之前,您可以设置属性

<input type="submit" disabled />