我已经很长时间没有用验证来编写代码了。我今天的问题是我正在尝试验证一个必须包含 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/