gpt4 book ai didi

javascript - 根据文本输入显示/隐藏 div

转载 作者:行者123 更新时间:2023-11-28 03:12:23 24 4
gpt4 key购买 nike

我想在用户输入“密码”的地方做一些事情,它会根据输入的密码显示一个 div。我看到类似这样的东西可以用数字工作,但我对如何让它用字母工作感到困惑.我怎样才能使这项工作?这是 JSfiddle:http://jsfiddle.net/3XGGn/405/

$(document).ready(function(){
$("#buttontest").click(function(){

if ($('#full_day').val() == yes) {
$("#yes").show("fast");
}
if ($('#full_day').val() == no) {
$("#no").show("fast");
}

else {
$("#yes").hide("fast");
$("#no").hide("fast");
$("#incorrect").show("500");
}
});
$("#full_day").change(function() {
$("#incorrect").hide("500");
});


});
#yes {display:none;}
#no {display:none;}
#incorrect {display:none;}
<p>type "yes" or "no"</p>
<div id="yes">
That's Correct!
</div>
<div id="no">
Also correct!
</div>
<div id="incorrect">
Sorry, Try again!
</div>
<input type='text' id="full_day"/>
<input type='button' id="buttontest" value="clickme"/>

最佳答案

试试这个它会接受任何大小写(小写/大写)的“yes”和“no”字符串,即使在混合大小写的情况下也是如此。

    <!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<meta charset="utf-8" />
<script>
$(document).ready(function () {
$("#buttontest").click(function () {
$(".all").hide("fast");
if ($('#full_day').val().toLocaleLowerCase() == "yes") {
$("#yes").show("fast");
} else if ($('#full_day').val().toLocaleLowerCase() == "no") {
$("#no").show("fast");
} else {
$("#incorrect").show("500");
}
});
$("#full_day").change(function () {
$("#incorrect").hide("500");
});
});
</script>
<style>
#yes {
display: none;
}

#no {
display: none;
}

#incorrect {
display: none;
}
</style>
</head>
<body>

<p>type "yes" or "no"</p>
<div class="all" id="yes">
That's Correct!
</div>
<div class="all" id="no">
Also correct!
</div>
<div class="all" id="incorrect">
Sorry, Try again!
</div>
<input type='text' id="full_day" />
<input type='button' id="buttontest" value="clickme" />
</body>
</html>

关于javascript - 根据文本输入显示/隐藏 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45644871/

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