Jquery模态视图问题
我有包含某种形式的模型视图。当我提交表单时,它调用 ajax 函数并使用 php 从数据库获取一些数据。它不会刷新。它工作正常,但如果我关闭模态并在提交请求时第二次打开,它会调用 ajax 函数 2 次。如果我关闭并重新打开模态视图3次调用。
当我调用模态视图时,我在其中包含新的 .php 文件。我还将 jquery 函数放入模态视图 .php 文件中。
每次打开模态视图时我都会添加脚本。它是否覆盖或添加两次相同的脚本?
这是我的 .js 函数
$('#contentArea #shareButton').click(function(){
var a = $("#watermark").val();
if(a != "What's on your mind?")
{
$.post("lib/actions/posts.php?value="+a, {
}, function(response){
$('#posting').prepend($(response).fadeIn('slow'));
$("#watermark").val("What's on your mind?");
});
}
});
$('.commentMark').livequery("focus", function(e){
var parent = $(this).parent();
$(".commentBox").children(".commentMark").css('width','320px');
$(".commentBox").children("a#SubmitComment").hide();
$(".commentBox").children(".CommentImg").hide();
var getID = parent.attr('id').replace('record-','');
$("#commentBox-"+getID).children("a#SubmitComment").show();
$('.commentMark').css('width','300px');
$("#commentBox-"+getID).children(".CommentImg").show();
});
//showCommentBox
$('a.showCommentBox').livequery("click", function(e){
var getpID = $(this).attr('id').replace('post_id','');
$("#commentBox-"+getpID).css('display','');
$("#commentMark-"+getpID).focus();
$("#commentBox-"+getpID).children("img.CommentImg").show();
$("#commentBox-"+getpID).children("a#SubmitComment").show();
});
//SubmitComment
$('a.comment').livequery("click", function(e){
var getpID = $(this).parent().attr('id').replace('commentBox-','');
var comment_text = $("#commentMark-"+getpID).val();
if(comment_text != "Write a comment...")
{
$.post("lib/actions/add_comment.php?comment_text="+comment_text+"&post_id="+getpID, {
}, function(response){
$('#CommentPosted'+getpID).append($(response).fadeIn('slow'));
$("#commentMark-"+getpID).val("Write a comment...");
});
}
});
//more records show
$('a.more_records').livequery("click", function(e){
var next = $(this).attr('id').replace('more_','');
$.post("lib/actions/posts.php?show_more_post="+next, {
}, function(response){
$('#bottomMoreButton').remove();
$('#posting').append($(response).fadeIn('slow'));
});
});
//deleteComment
$('a.c_delete').livequery("click", function(e){
if(confirm('Are you sure you want to delete this comment?')==false)
return false;
e.preventDefault();
var parent = $(this).parent();
var c_id = $(this).attr('id').replace('CID-','');
$.ajax({
type: 'get',
url: 'lib/actions/delete_comment.php?c_id='+ c_id,
data: '',
beforeSend: function(){
},
success: function(){
parent.fadeOut(200,function(){
parent.remove();
});
}
});
});
/// hover show remove button
$('.friends_area').livequery("mouseenter", function(e){
$(this).children("a.delete").show();
});
$('.friends_area').livequery("mouseleave", function(e){
$('a.delete').hide();
});
/// hover show remove button
$('a.delete').livequery("click", function(e){
if(confirm('Are you sure you want to delete this post?')==false)
return false;
e.preventDefault();
var parent = $(this).parent();
var temp = parent.attr('id').replace('record-','');
var main_tr = $('#'+temp).parent();
$.ajax({
type: 'get',
url: 'lib/actions/delete.php?id='+ parent.attr('id').replace('record-',''),
data: '',
beforeSend: function(){
},
success: function(){
parent.fadeOut(200,function(){
main_tr.remove();
});
}
});
});
$('textarea').elastic();
jQuery(function($){
$("#watermark").Watermark("What's on your mind?");
$(".commentMark").Watermark("Write a comment...");
});
jQuery(function($){
$("#watermark").Watermark("watermark","#369");
$(".commentMark").Watermark("watermark","#EEEEEE");
});
function UseData(){
$.Watermark.HideAll();
//Do Stuff
$.Watermark.ShowAll();
}
I have model view that contains some form. When I submit form it calls ajax function and gets some data from database with php.It does not make refresh.It works normal but if I close modal and open second time when i submit request it calls ajax function 2 times.If I close and re open modal view 3 times calls.
When I call my modal view I include new .php file in it.I put my jquery function in modal view .php file also.
And I am adding my script each time when I open modal view. is it overwrites or adds two time same script?
this is my .js function
$('#contentArea #shareButton').click(function(){
var a = $("#watermark").val();
if(a != "What's on your mind?")
{
$.post("lib/actions/posts.php?value="+a, {
}, function(response){
$('#posting').prepend($(response).fadeIn('slow'));
$("#watermark").val("What's on your mind?");
});
}
});
$('.commentMark').livequery("focus", function(e){
var parent = $(this).parent();
$(".commentBox").children(".commentMark").css('width','320px');
$(".commentBox").children("a#SubmitComment").hide();
$(".commentBox").children(".CommentImg").hide();
var getID = parent.attr('id').replace('record-','');
$("#commentBox-"+getID).children("a#SubmitComment").show();
$('.commentMark').css('width','300px');
$("#commentBox-"+getID).children(".CommentImg").show();
});
//showCommentBox
$('a.showCommentBox').livequery("click", function(e){
var getpID = $(this).attr('id').replace('post_id','');
$("#commentBox-"+getpID).css('display','');
$("#commentMark-"+getpID).focus();
$("#commentBox-"+getpID).children("img.CommentImg").show();
$("#commentBox-"+getpID).children("a#SubmitComment").show();
});
//SubmitComment
$('a.comment').livequery("click", function(e){
var getpID = $(this).parent().attr('id').replace('commentBox-','');
var comment_text = $("#commentMark-"+getpID).val();
if(comment_text != "Write a comment...")
{
$.post("lib/actions/add_comment.php?comment_text="+comment_text+"&post_id="+getpID, {
}, function(response){
$('#CommentPosted'+getpID).append($(response).fadeIn('slow'));
$("#commentMark-"+getpID).val("Write a comment...");
});
}
});
//more records show
$('a.more_records').livequery("click", function(e){
var next = $(this).attr('id').replace('more_','');
$.post("lib/actions/posts.php?show_more_post="+next, {
}, function(response){
$('#bottomMoreButton').remove();
$('#posting').append($(response).fadeIn('slow'));
});
});
//deleteComment
$('a.c_delete').livequery("click", function(e){
if(confirm('Are you sure you want to delete this comment?')==false)
return false;
e.preventDefault();
var parent = $(this).parent();
var c_id = $(this).attr('id').replace('CID-','');
$.ajax({
type: 'get',
url: 'lib/actions/delete_comment.php?c_id='+ c_id,
data: '',
beforeSend: function(){
},
success: function(){
parent.fadeOut(200,function(){
parent.remove();
});
}
});
});
/// hover show remove button
$('.friends_area').livequery("mouseenter", function(e){
$(this).children("a.delete").show();
});
$('.friends_area').livequery("mouseleave", function(e){
$('a.delete').hide();
});
/// hover show remove button
$('a.delete').livequery("click", function(e){
if(confirm('Are you sure you want to delete this post?')==false)
return false;
e.preventDefault();
var parent = $(this).parent();
var temp = parent.attr('id').replace('record-','');
var main_tr = $('#'+temp).parent();
$.ajax({
type: 'get',
url: 'lib/actions/delete.php?id='+ parent.attr('id').replace('record-',''),
data: '',
beforeSend: function(){
},
success: function(){
parent.fadeOut(200,function(){
main_tr.remove();
});
}
});
});
$('textarea').elastic();
jQuery(function($){
$("#watermark").Watermark("What's on your mind?");
$(".commentMark").Watermark("Write a comment...");
});
jQuery(function($){
$("#watermark").Watermark("watermark","#369");
$(".commentMark").Watermark("watermark","#EEEEEE");
});
function UseData(){
$.Watermark.HideAll();
//Do Stuff
$.Watermark.ShowAll();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您每次调用时都会创建模态视图吗?您可能想重用,因为它看起来就像多次创建它然后提交所有这些。
Are you creating the modal view each time you call it? You maybe want to reuse, because it seams like creating it multiple times and then just submits all of them.