gpt4 book ai didi

javascript - 我想使用 jquery 一旦每个字段都有值就显示消息

转载 作者:行者123 更新时间:2023-12-02 19:57:31 25 4
gpt4 key购买 nike

我的html:

<html>
<body>
<input type="text" id="name" name="name" placeholder="First Name" />
<label for="name">First Name </label>
<button id="submit" src="images/button.png" width="100" >Submit</button>
</body>
</html>

我的脚本是:

<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function() {
var emptyTextBoxes = $('input[type=text],[type=password]').filter(function() { return this.value == "";
});
emptyTextBoxes.each(function() {
$(emptyTextBoxes).nextAll('label').css({'display':'inline','color':'#F00'});
});
});

一旦我在文本字段中输入值,我想显示消息(表单提交)如何将该警报消息放在这里

最佳答案

完全重新设计的版本,将您的输入字段放入表单中并更正原始 JavaScript 中的错误...

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
// use the id of the form (moved from the button)
$('#submit').bind('submit',function(){
// I added `input` in front of your password selector to make it more accureate/efficient
var emptyTextBoxes = $('input[type=text],input[type=password]').filter(function(){
return this.value == "";
});
// if there are no empty boxes
if(!emptyTextBoxes.length){
alert('We finally did it')
}
// this prevents the form from being submitted
return false;
})
})
</script>
</head>
<body>
<!-- wrap with form and give form id -->
<form action='#' method='POST' id="submit">
<input type="text" id="name" name="name" placeholder="First Name" />
<label for="name">First Name </label>
<!-- replace button with submit input -->
<input type='submit' width="100" />
</form>
</body>
</html>

关于javascript - 我想使用 jquery 一旦每个字段都有值就显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8428658/

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