gpt4 book ai didi

javascript - Jquery启用/禁用按钮文本区域验证

转载 作者:行者123 更新时间:2023-12-01 00:12:01 25 4
gpt4 key购买 nike

Jsfiddle example

举个例子,我想做这个操作。它不能单独工作。我把它放在我的服务器上,当我运行它时它不起作用错误在哪里?

$( "#validateTxt" ).change(function() {
if($( "#validateTxt" ).val()=="123"){
$('#btnCheck').attr("enabled",false);
}
else{
$('#btnCheck').attr("disabled",true);
}

});
<!DOCTYPE html>
<html lang="en" >
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title></title>


</head>
<body>
<!-- partial:index.partial.html -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>

////üst kodlar boostrap kütüphanesini çağırıdıgım kodlar projende yoksa ekle

<input type="text" id="validateTxt" class="form-control" placeholder="123">


<input type="button" class="btn btn-success" value="KontrolEt" id="btnCheck" disabled>
<!-- partial -->
<script src="./script.js"></script>


</body>
</html>

最佳答案

你可以这样做

$('#btnCheck').attr("disabled", false);

Html 没有 enabled 属性。因此需要将 disabled 属性设置为 false

$("#validateTxt").change(function() {
if ($("#validateTxt").val() == "123") {
$('#btnCheck').attr("disabled", false);
} else {
$('#btnCheck').attr("disabled", true);
}

});
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title></title>


</head>

<body>
<!-- partial:index.partial.html -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>

////üst kodlar boostrap kütüphanesini çağırıdıgım kodlar projende yoksa ekle

<input type="text" id="validateTxt" class="form-control" placeholder="123">


<input type="button" class="btn btn-success" value="KontrolEt" id="btnCheck" disabled>
<!-- partial -->
<script src="./script.js"></script>


</body>

</html>

关于javascript - Jquery启用/禁用按钮文本区域验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60014704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com