jQuery为<input />标签添加“disable”和去除“disable”属性

本文展示了如何使用JavaScript来禁用和启用HTML输入标签的按钮,通过修改DOM属性实现按钮状态的切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$("#subButton").attr("disabled","disabled");//禁用input标签
$("#subButton").attr("disabled",false);//启用input标签
<html> <head> <script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可选的 Bootstrap 主题文件(一般不用引入) --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script lang="javascript"> </script> </head> <body> <form> <div style="width:500px;margin:10px auto;text-align: center;"> <div style="font-size:28px;font-weight:bold;margin:0px auto;">user signup</div> <br /> <table style="width:100%;text-align: left;"> <tbody> <tr style="margin-bottom: 20px;"> <td> <span class="p">*</span> <label for="username" class="l"> new username:</label> </td> <td> <input id="username" type="text" style="height:30px;width:250px;padding-right:50px;"> </td> </tr> <tr> <td><br></td> <td></td> </tr> <tr style="margin-bottom: 20px;"> <td> <span class="p">*</span> <label for="password" class="l"> password:</label> </td> <td> <input id="password" type="text" style="height:30px;width:250px;padding-right:50px;"> </td> </tr> <tr> <td><br></td> <td></td> </tr> <tr style="margin-bottom: 20px;"> <td> <span class="p">*</span> <label for="passwordc" class="l"> repeated password:</label> </td> <td> <input id="passwordc" type="text" style="height:30px;width:250px;padding-right:50px;"> </td> </tr> <tr> <td><br></td> <td></td> </tr> <tr> <td> </td> <td> <input class="btn btn-success" type="button" style="margin:0 auto;width:250px;" value="click to signup" onclick='onSignup()' /> <label name='login_hint' id='login_hint' style='display:none'>sigup success!</label> </td> </tr> </tbody> </table> </div> </form> </body> <script lang="javascript"> function onSignup() { var username = document.getElementById('username'); var password = document.getElementById('password'); $.ajax({ url: "/user/signup", type: "POST", data: { "username": username.value, "password": password.value }, error: function (jqXHR, textStatus, errorThrown) { if (textStatus == "error") { alert(textStatus + " : " + errorThrown); } else { alert(textStatus); } }, success: function (data, textStatus, jqXHR) { if (data == 'SUCCESS') { // 成功后跳到登录页 document.getElementById("login_hint").style.display = "block"; setTimeout(() => { window.location.href = '/static/view/signin.html'; }, 2000); } else { alert('signup fail!'); } } }); } </script> </html> 换成https后还是出现错误
03-27
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="zh-CN" class="bootstrap-admin-vertical-centered"> <head> <meta charset="UTF-8"> <title>图书馆管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="static/css/bootstrap.min.css"> <link rel="stylesheet" href="static/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="static/css/bootstrap-admin-theme.css"> <link rel="stylesheet" href="static/css/bootstrap-admin-theme.css"> <script src="static/js/bootstrap.min.js"></script> <script src="static/jQuery/jquery-3.1.1.min.js"></script> <script src="static/ajax-lib/ajaxutils.js"></script> <script src="static/js/login.js"></script> </head> <style type="text/css"> .alert{ margin: 0 auto 20px; text-align: center; } </style> <script src="static/js/jquery.min.js"></script> <script src="static/js/bootstrap.min.js"></script> <body class="bootstrap-admin-without-padding"> 池州学院 230312242 杨洪博 课设 <div style="background-image: url('image/2.png'); background-size: cover; background-repeat: no-repeat; background-position: center;"></div> <div class="col-lg-12"> <div class="alert alert-info"> <a class="close" data-dismiss="alert" href="#">×</a> 欢迎登录图书馆管理系统 </div> <form class="bootstrap-admin-login-form" method="post" action="/books/LoginServlet"> <% String state = (String)session.getAttribute("state"); session.removeAttribute("state"); if(state!=null){ %> <label class="control-label" for="username">密码错误</label> <%}%> <div class="form-group"> <label class="control-label" for="username">账 号</label> <input type="text" class="form-control" id="username" name="username" required="required" placeholder="学号"/> <label class="control-label" for="username" style="display:none;"></label> </div> <div class="form-group"> <label class="control-label" for="password">密 码</label> <input type="password" class="form-control" id="password" name="password" required="required" placeholder="密码"/> <label class="control-label" for="username" style="display:none;"></label> </div> <label class="control-label" for="password">没有账号请<a href="/books/register.jsp" style="color:blue;">注册</a></label> <br> <input type="submit" class="btn btn-lg btn-primary" value="登    录"/> </form> </div> </div> </div> <div class="modal fade" id="modal_info" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="infoModalLabel">提示</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-lg-12" id="div_info"></div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" id="btn_info_close" data-dismiss="modal">关闭</button> </div> </div> </div> </div> </body> </html>文件路径没问题 但图片显示不出来
最新发布
06-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值