gpt4 book ai didi

javascript - 在函数内的 If 语句中插入 JQuery

转载 作者:行者123 更新时间:2023-11-28 19:13:40 25 4
gpt4 key购买 nike

我已经很长时间没有用验证来编写代码了。我今天的问题是我正在尝试验证一个必须包含 10 个或以上字符的字段。当您按“确定”时,jQuery 函数应该会触发。

function pathvalid() {
var str = document.getElementById("pathenabler");
var n = str.value.length;
if (n < 10) {
document.getElementById("demo").innerHTML = "The path that you have entered is either invalid or incorrect. Please input a valid path.";
}
else {
document.getElementById("demo").innerHTML = "Not Good day!";
$('.actionenabler') .removeClass('chkbox');
}
}

最佳答案

只需将其添加到“确定”按钮即可

<input type="button" value="OK" onclick="pathvalid();" />

或者

您可以使用 jquery 编写代码。您的输入按钮

 <input type="button" value="OK" id="btn"/>

您的 JavaScript 包含:

$(document).ready(function(){
$("#btn").click(function(){
if($("#pathenabler").text().trim().length < 10){
$("#demo").append("The path that you have entered is either invalid or incorrect. Please input a valid path.");
}
else{
$("#demo").append("Not Good day!");
$('.actionenabler').removeClass('chkbox');
}
});
});

关于javascript - 在函数内的 If 语句中插入 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30305146/

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