gpt4 book ai didi

javascript - 使用函数调用调用 jquery 弹出窗口

转载 作者:行者123 更新时间:2023-11-28 06:24:19 27 4
gpt4 key购买 nike

提交表单后,下面的行会打开一个弹出模式。

<input class="js__p_start" type="submit"  value="submit" name="submit"/>

我不想在提交表单后打开弹出窗口。提交表单后,使用ajax将数据发送到php。我想在成功的ajax请求后打开弹出窗口。Ajax代码如下,

<script>

$(document).ready(function(){
$("#hidden_form").submit(function(){
var mobile = $("#mobile").val();
var name = $("#name").val();


var dataString = 'mobile='+ mobile + '&name='+ name;

if(name=='')
{
alert("Please Enter your name");
}
else
{

$.ajax({
type: "POST",
url: "file.php",
data: dataString,
cache: false,
success: function(result){

//I Want to call Popup here, so that popup will appear only after user properly entereed form fields

}
});
}
return false;
});
});
</script>

这是 JS 文件:

(function($) {
$.fn.simplePopup = function(event) {
var simplePopup = {
settings: {
hashtag: "#/",
url: "popup",
event: event || "click"
},

initialize: function(link) {
var popup = $(".js__popup");
var body = $(".js__p_body");
var close = $(".js__p_close");
var routePopup = simplePopup.settings.hashtag + simplePopup.settings.url;

var cssClasses = link[0].className;

if (cssClasses.indexOf(" ") >= 0) {
cssClasses = cssClasses.split(" ");

for (key in cssClasses) {
if (cssClasses[key].indexOf("js__p_") === 0) {
cssClasses = cssClasses[key]
}
};
}

var name = cssClasses.replace("js__p_", "");

// We redefine the variables if there is an additional popap
if (name !== "start") {
name = name.replace("_start", "_popup");
popup = $(".js__" + name);
routePopup = simplePopup.settings.hashtag + name;
};

link.on(simplePopup.settings.event, function() {
simplePopup.show(popup, body, routePopup);
return false;
});

$(window).on("load", function() {
simplePopup.hash(popup, body, routePopup);
});

body.on("click", function() {
simplePopup.hide(popup, body);
});

close.on("click", function() {
simplePopup.hide(popup, body);
return false;
});

$(window).keyup(function(e) {
if (e.keyCode === 27) {
simplePopup.hide(popup, body);
}
});
},


centering: function(popup) {
var marginLeft = -popup.width()/2;
return popup.css("margin-left", marginLeft);
},

show: function(popup, body, routePopup) {
simplePopup.centering(popup);
body.removeClass("js__fadeout");
popup.removeClass("js__slide_top");
location.hash = routePopup;
document.getElementById("menu_but").style.visibility = "hidden";
document.getElementById("toTop").style.visibility = "hidden";
document.getElementById("cbp-spmenu-s1").style.visibility = "hidden";
},

hide: function(popup, body) {
popup.addClass("js__slide_top");
body.addClass("js__fadeout");
location.hash = simplePopup.settings.hashtag;
document.getElementById("menu_but").style.visibility = "visible";
document.getElementById("toTop").style.visibility = "visible";
document.getElementById("cbp-spmenu-s1").style.visibility = "visible";
},

hash: function(popup, body, routePopup) {
if (location.hash === routePopup) {
simplePopup.show(popup, body, routePopup);
}
}
};


return this.each(function() {
var link = $(this);
simplePopup.initialize(link);
});
};
})(jQuery);

基本上,我正在寻找 AJAX 成功部分中的一些函数调用来获取弹出模式。

最佳答案

js 文件中的函数是立即调用函数 IIF,这就是为什么它会自行执行,并且您会看到弹出窗口.

您需要删除函数表达式前后的括号,以使其表现得像普通函数一样。您可以将此函数耐火为

function someFunctionName(){
// you code goes here

}

然后在ajax成功 block 中您可以调用someFunctionName()

关于javascript - 使用函数调用调用 jquery 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35254173/

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