jquery simplemodal无法调用另一个函数
在我的模式窗口中,我有一个“继续”按钮。虽然我可以通过为按钮分配 simplemodal-close 类来关闭模式,但我无法让它调用我的函数。我从网站上的简单演示中整理了这段代码。
按钮:
<a href="#" class="simplemodal-close" onClick="closePopup()"><img src="bell/images/button_understand.gif" width="116" height="49"></a>
javascript:
$(document).ready(function() {
function showPopups(){
var e = document.getElementById('hirpopup');
$('#hirpopup').modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
});
e.style.display = 'block';
return false;
}
function closePopup(){
var e = document.getElementById('hirpopup');
e.style.display = 'none';
confirm(function () {
sameWindow(this.form);
});
}
function confirm(callback) {
$('#hirpopup').modal({
onShow: function () {
var modal = this;
// call the callback
if ($.isFunction(callback)) {
callback.apply();
}
}
});
}
});
任何想法,因为我对 jQuery 很陌生,对 simplemodal 完全陌生。
编辑:我已经更新了我的 JavaScript,如下所示,但它仍然没有执行我的功能。我收到警报 1,并且警报中包含该功能,但没有其他内容。
$(document).ready(function(){
$("#close").css("cursor", "pointer");
$('#next').click(function(){
var e = document.getElementById('hirpopup');
$('#hirpopup').modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
});
e.style.display = 'block';
return false;
});
$('#close').click(function(){
var e = document.getElementById('hirpopup');
e.style.display = 'none';
confirm(function () {
sameWindow(this.form);
});
});
});
function confirm(callback) {
alert("1");
alert(callback);
$('#hirpopup').modal({
onShow: function () {
alert("2");
var modal = this;
// call the callback
if ($.isFunction(callback)) {
alert("3");
callback.apply();
}
}
});
}
In my modal window I have a "continue" button. Whilst I can get the modal to close by assigning the button with the simplemodal-close class, I can't get it to call my function. I've put together this code from the simple demos on the site.
The button:
<a href="#" class="simplemodal-close" onClick="closePopup()"><img src="bell/images/button_understand.gif" width="116" height="49"></a>
the javascript:
$(document).ready(function() {
function showPopups(){
var e = document.getElementById('hirpopup');
$('#hirpopup').modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
});
e.style.display = 'block';
return false;
}
function closePopup(){
var e = document.getElementById('hirpopup');
e.style.display = 'none';
confirm(function () {
sameWindow(this.form);
});
}
function confirm(callback) {
$('#hirpopup').modal({
onShow: function () {
var modal = this;
// call the callback
if ($.isFunction(callback)) {
callback.apply();
}
}
});
}
});
Any ideas as I'm pretty new to jQuery and completely new to simplemodal.
EDIT: I've updated my javascript as follows, however its still not doing my function. I get the alert of 1, and the alert with the function in it but nothing else.
$(document).ready(function(){
$("#close").css("cursor", "pointer");
$('#next').click(function(){
var e = document.getElementById('hirpopup');
$('#hirpopup').modal({
opacity:80,
overlayCss: {backgroundColor:"#fff"}
});
e.style.display = 'block';
return false;
});
$('#close').click(function(){
var e = document.getElementById('hirpopup');
e.style.display = 'none';
confirm(function () {
sameWindow(this.form);
});
});
});
function confirm(callback) {
alert("1");
alert(callback);
$('#hirpopup').modal({
onShow: function () {
alert("2");
var modal = this;
// call the callback
if ($.isFunction(callback)) {
alert("3");
callback.apply();
}
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:您可以尝试将确认方法放入 document.ready 中。这可能是一个问题
您不能在自己的函数中使用 $(document).ready,但它应该是根方法。还可以使用 jQuery 事件绑定
});
EDIT: you may try to put confirm method inside document.ready. This could be one issue
You cannot have $(document).ready inside your own function, but it should be the root method. Use also the jQuery event binding
});
您的函数中不能有
$(document).ready(function(){})
。它仅在页面加载时自动执行一次。而是写
You cannot have
$(document).ready(function(){})
inside your function. It executes automatically only once when your page gets loaded.instead write