我在java中使用struts 1.1,它有动作,形式和bo.To更快我也在我的code.i中使用ajax成功地使用ajax将数据提取到网格中。下一个任务是当用户点击单个复选框时行将打开一个新窗口。但问题是复选框操作在第一次单击时不起作用,它只能在chrome中的第二次单击工作。它在IE和firefox的上层版本中顺利工作。注意我正在使用jquery 1.9 .1图书馆。 这是我的Jsp代码---------
//This is checkbox calling function............
function openWinForChequeDetails(f){
$(document).ready(function(){
// $('.chk').val($(this).is(':checked'));
//Attach button clicke event handler
$('.chk').change(function () {
//Loop through each checkbox in table
$("table tr td input[type=checkbox]");
//Check if checkbox nis checked or not
if ($(this).is(':checked')) {
//if checked then get the value
var v1 = $(this).parent().siblings('td').eq(1).text();
var Asondate = document.postOutwardClearingChequesForm.asOnDate.value;
var flg = 'Y';
alert("CHeckbox==>"+flg);
winURL="/mybank/chequeDetailsPostOutwardClearingCheques.do?batchNumber="+v1+"&docDate="+Asondate+"&flag="+flg;
winName = "PostOutwardClearingChequesDetails";
winHeight = 380;
winWidth = screen.availWidth - 15;
winTop = ((screen.availHeight/2) - (winHeight / 6));
winLeft = 0;
winOpen = "";
if(winOpen){
if(winOpen.closed){
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
} else {
winOpen.close();
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
}
} else {
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
}
winOpen.focus();
} else{
var flg='N' ;
alert(flg);
$.ajax({
url:'/mybank/unChequeDetailsPostOutwardClearingCheques.do?batchNumber='+v1+'&docDate='+Asondate+'&flag='+flg,
type:'post',
dataType: 'json'
});
}Console.log("Quite Method");
});
});
}
//This is Ajax Calling from gridview..................
var rowNew= $('<td align="center" class="lbl-08" width="9%"></td>').html('<input type="checkbox" onclick="openWinForChequeDetails(postOutwardClearingChequesForm)" class="chk" value="Y" indexed="true" />').appendTo(tr);
答案 0 :(得分:0)
将您的JS功能更改为此。您在此方案中不需要$(document).ready
或$('.chk').change
,因为您已在onclick
事件中直接调用该函数。
//This is checkbox calling function............
function openWinForChequeDetails(f, elem){
//Loop through each checkbox in table
//Check if checkbox is checked or not
if ($(elem).is(':checked')) {
//if checked then get the value
var v1 = $(elem).parent().siblings('td').eq(1).text();
var Asondate = document.postOutwardClearingChequesForm.asOnDate.value;
var flg = 'Y';
alert("CHeckbox==>"+flg);
winURL="/mybank/chequeDetailsPostOutwardClearingCheques.do?batchNumber="+v1+"&docDate="+Asondate+"&flag="+flg;
winName = "PostOutwardClearingChequesDetails";
winHeight = 380;
winWidth = screen.availWidth - 15;
winTop = ((screen.availHeight/2) - (winHeight / 6));
winLeft = 0;
winOpen = "";
if(winOpen){
if(winOpen.closed){
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
} else {
winOpen.close();
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
}
} else {
winOpen = window.open(winURL, winName, "top=" + winTop + ",left=" + winLeft + ",width=" + winWidth + ",height=" + winHeight + ",resizable=no,toolbar=no,scrollbars=yes,location=no,status=no,menubar=no")
}
winOpen.focus();
} else{
var flg='N' ;
alert(flg);
$.ajax({
url:'/mybank/unChequeDetailsPostOutwardClearingCheques.do?batchNumber='+v1+'&docDate='+Asondate+'&flag='+flg,
type:'post',
dataType: 'json'
});
}Console.log("Quite Method");
}
你的Ajax电话:
//This is Ajax Calling from gridview..................
var rowNew= $('<td align="center" class="lbl-08" width="9%"></td>').html('<input type="checkbox" onclick="openWinForChequeDetails(postOutwardClearingChequesForm, this)" class="chk" value="Y" indexed="true" />').appendTo(tr);