【发布时间】:2011-05-05 21:03:34
【问题描述】:
您好,当我的脚本完成处理后,我遇到了使用 jquery 覆盖无法关闭的问题。
我所做的只是显示一个非常简单的表单,获取提交时在后台处理它们的值并将它们添加到页面中。完成此操作后,覆盖应该关闭,但它只是停留在那里,直到我刷新整个页面时才会消失。
我的 Jquery 代码如下所示:
function employmenthistory(){
$(document).ready(function(){
/**
* Modal Dialog Boxes Setup
*/
var triggers = $(".modalInput").overlay({
// some mask tweaks suitable for modal dialogs
mask: {
color: '#ebecff',
loadSpeed: 200,
opacity: 0.7
},
closeOnClick: false
});
/* User Input Prompt Modal Box */
$("#employmentprompt form").submit(function(e) {
// get user input
var name = $("#name", this).val();
var role = $('#role', this).val();
var title = $("#title", this).val();
//we need to know how many elements already exist
var elementCount = $('li.note').length;
//update server with information about this employment
$.ajax({
url: '/addempl/',
type : 'post',
data : "name=" + name + "&role=" + role + "&title=" + title + "&ec=" + elementCount,
dataType: "json",
success : function(msg){
//confirm the event was successful
if(msg.status == 'success'){
var item = msg.data;
//we now add to the ul for elements
$('ul.listing').append(item);
}else{
//failed to process so display error
$('div.message error').html('<p>We were unable to add your employment history</p><p>Please try again</p>');
}
},
error : function(err){
//failed to call server
$('div.message error').html('<p>We were unable to add your employment history</p><p>Please try again</p>');
}
});
// close the overlay
triggers.eq(0).overlay().close();
// do not submit the form
return e.preventDefault();
});
});
}
这段代码的所有方面都可以正常工作,除了我到达时
triggers.eq(0).overlay().close();
其中包含表单的叠加层仍保留在页面上。只有一个 modelInput 元素和表单可以调用,所以我不确定为什么会失败。
我所做的只是按照可以在此处找到的示例:
http://flowplayer.org/tools/demos/overlay/modal-dialog.html
我们将不胜感激地收到任何帮助。
谢谢。
【问题讨论】:
标签: jquery jquery-ui jquery-plugins