gpt4 book ai didi

javascript - 在输入字段中输入文本之前,如何禁用提交按钮?

转载 作者:太空狗 更新时间:2023-10-29 13:22:03 25 4
gpt4 key购买 nike

我在尝试实现此结果时遇到问题,我几乎需要的是在输入字段中输入文本之前禁用提交按钮。我尝试了一些功能但没有结果。

HTML 标记

<form action="" method="get" id="recipename">
<input type="text" id="name" name="name" class="recipe-name"
value="Have a good name for it? Enter Here"
onfocus="if (this.value == 'Have a good name for it? Enter Here') {this.value = '';}"
onblur="if (this.value == '') {this.value = 'Have a good name for it? Enter Here';}"
/>
<input type="submit" class="submit-name" value="" />
</form>

最佳答案

你可以使用这个:

var initVal = "Have a good name for it? Enter Here";
$(document).ready(function(){
$(".submit-name").attr("disabled", "true");
$(".recipe-name").blur(function(){
if ($(this).val() != initVal && $(this).val() != "") {
$(".submit-name").removeAttr("disabled");
} else {
$(".submit-name").attr("disabled", "true");
}
});
});

参见jsfiddle .

关于javascript - 在输入字段中输入文本之前,如何禁用提交按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3742050/

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