[英]How to set condition inside Jquery .Live () function
I am calling live('click')
function in which i call ajax method and do some server side functionality. 我正在调用
live('click')
函数,在其中我调用ajax方法并执行一些服务器端功能。
But before ajax call i need to check
for valid data
. 但是在ajax调用之前,我需要
check
valid data
。 Am bit confused how to call it 有点困惑如何称呼它
// Depend on this condition i have to start process my ajax function.
function validData()
{
if ($('.edt').val() == "")
{
return false;
}
var maxtxtvalue = $('edt3').val();
var mintxtvalue = $('edt4').val();
// alert(maxtxtvalue > mintxtvalue);
if(parseInt(maxtxtvalue) > parseInt(mintxtvalue))
{
return true;
}
else
{
$('input:text[id$="txtmaxctc"]').val('');
$('input:text[id$="txtminctc"]').val('');
alert("Max ctc must be greater then Min ctc.");
return false;
}
}
$("img[class^='sav_']").live('click', function (event) {
if( return false )
{
}
else{
//start process
$.ajax({
type: "POST",
url: "ajax_function/updatefn.asmx/upajx",
data: "{ 'prefix': '" + dataString + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
} });
}
});
// Depend on this condition i have to start process my ajax function. //根据这种情况,我必须开始处理我的ajax函数。
can't you do like this.. 你不能这样吗..
function validData()
{
if ($('.edt').val() == "")
{
return false;
}
var maxtxtvalue = $('edt3').val();
var mintxtvalue = $('edt4').val();
// alert(maxtxtvalue > mintxtvalue);
if(parseInt(maxtxtvalue) > parseInt(mintxtvalue))
{
return true;
}
else
{
$('input:text[id$="txtmaxctc"]').val('');
$('input:text[id$="txtminctc"]').val('');
alert("Max ctc must be greater then Min ctc.");
return false;
}
}
$("img[class^='sav_']").live('click', function (event) {
if(validData() )
{
}
else{
//start process
$.ajax({
type: "POST",
url: "ajax_function/updatefn.asmx/upajx",
data: "{ 'prefix': '" + dataString + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
} });
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.