gpt4 book ai didi

javascript if 语句执行但互相阻塞?

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

如果正在执行语句但未显示结果,则结果文本会显示几分之一秒,并很快被另一个结果删除

<script>
function validateEmail($email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test($email);
}

function myFunction() {
var user = $('#user-name').val();
var userpass = $('#user-password1').val();
var userpass1 = $('#user-password2').val();
var useremail = $('#user-email').val();
var passMatch = false;
var nameValid = false;
var emailValid = false;
//Check Username availability
if ($.trim(user) != '') {
$.post('includes/checkUserName.php', {
checkUser: user
}, function(checkData) {
$('#regErrors').text(checkData);
});
}
//Check Email availability
if ($.trim(useremail) != '') {
$.post('includes/checkEmail.php', {
checkE: useremail
}, function(checkEmail) {
$('#regErrors').text(checkEmail);
});
}
if ($.trim(userpass) != userpass1) {
$('#regErrors').text("Passwords must match")
}
if ($.trim(user) == '' || $.trim(userpass) == '' || $.trim(userpass1) == '' || $.trim(useremail) == '') {
$('#regErrors').text("All fields required")
}
}
</script>

最佳答案

您将使用 .text() 方法替换每个帖子上的内容,而是附加一个标签:

$('#regErrors').append($("<p />", {html: checkData}));
$('#regErrors').append($("<p />", {html: checkEmail}));
$('#regErrors').append($("<p />", {html: "Passwords must match"}));
$('#regErrors').append($("<p />", {html: "All fields required"}));

关于javascript if 语句执行但互相阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32260824/

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