这是我第一次使用HTML,并希望合并一个复选框,启用或禁用"登录"按钮,如果用户没有勾选复选框以同意,并在方框勾选时启用按钮。
<td>
<input style="width: 80px" name="username" type="text" value="$(username)" />
</td>
</tr>
<tr>
<td align="right" class="style6">Password</td>
<td>
<input style="width: 80px" name="password" type="password" />
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" value="Login" />
</td>
</tr>
</table>
<div class="notice" style="color: #c1c1c1; font-size: 12px">
<br />
<input type="checkbox" name="checkbox" value="check" id="agree" />I agree to the statement above.
<br />
</div>
&#13;
答案 0 :(得分:1)
<form>
<input type="checkbox" name="1" value="1" required>
<input type="submit">
</form>
答案 1 :(得分:0)
你可以使用这样的一些javascript来做到这一点:
<input type="checkbox" name="checkbox" value="check" id="agree" onclick="if(this.checked){ document.getElementById('login').disabled=true; }else{ document.getElementById('login').disabled=false; }" />
您只需在提交按钮上提供ID即可!
答案 2 :(得分:0)
如果你想用javascript做,你可以尝试这个(在我看来使用@Quention解决方案更好)
document.getElementById("submit").disabled = true;
function agree() {
if (document.getElementById('agree').checked) {
document.getElementById("submit").disabled = false;
} else {
document.getElementById("submit").disabled = true;
}
}
<td><input style="width: 80px" name="username" type="text" value="$(username)" required/></td>
</tr>
<tr>
<td align="right" class="style6">Password</td>
<td><input style="width: 80px" name="password" type="password"/></td>
</tr>
<tr>
<td> </td>
<td><input id="submit" type="submit" name="submit" value="Login" /></td>
</tr>
</table>
<div class="notice" style="color: #c1c1c1; font-size: 12px"><br />
<input type="checkbox" name="checkbox" value="check" id="agree" onclick="agree()" required/> I agree to the statement above.
<br q v/>
</div>