我有一个带有 onclientclick 和 onclick 事件的按钮。我的页面中也有一个 jquery。此 jquery 在计时器 elpase 时注册按钮单击事件。OnclientClick 调用一个函数来验证是否单击了单选按钮...当计时器运行时...如果用户单击(下一步)按钮而不选择选项(radiobuttonList)...它返回 false,因此服务器侧面事件被阻止..但是,如果计时器过去并且没有选择任何项目,则提交表单时带有空白选项这里是代码,
var countdownTimer, countdownCurrent;
$(document).ready(function() {
countdownCurrent = $('#ctl00_MainContent_example2submit').val() * 100;
countdownTimer = $.timer(function () {
var min = parseInt(countdownCurrent / 6000);
var sec = parseInt(countdownCurrent / 100) - (min * 60);
var micro = pad(countdownCurrent - (sec * 100) - (min * 6000), 2);
var output = "00"; if (min > 0) { output = pad(min, 2); }
$('.countdowntime').html(output + ":" + pad(sec, 2) + ":" + micro);
if (countdownCurrent == 0) {
$('#ctl00_MainContent_btnNext').click();
} else {
countdownCurrent -= 7;
if (countdownCurrent < 0) {
countdownCurrent = 0;
}
}
}, 70, true);
$('#example2submit').bind('keyup', function (e) {
if (e.keyCode == 13) {
countdownReset();
}
});
function CheckIfOptionSelected() {
var vFlag = true;
var radioButton1 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_0'];
var radioButton2 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_1'];
var radioButton3 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_2'];
var radioButton4 = document.forms[0].elements['ctl00_MainContent_rdBtnListOptions_3'];
if (radioButton1.checked == false && radioButton2.checked == false && radioButton3.checked == false && radioButton4.checked == false && countdownCurrent > 0) {
vFlag = false;
}
else {
countdownReset();
vFlag = true;
}
return vFlag;
}
function countdownReset() {
var newCount = parseInt($('#ctl00_MainContent_example2submit').val()) * 100;
if (newCount > 0) { countdownCurrent = newCount; }
}
我面临的问题是,如果我允许计时器在单选按钮列表中没有选择任何内容的情况下过去... Onclick 事件触发,成功回发,但是当我选择一个选项...并且没有单击 NEXT 按钮我让计时器过去....回发不发生??....下一步按钮如下:
<asp:Button ID="btnNext" runat="server" Height="26px"
OnClientClick="if(!CheckIfOptionSelected()){return false;};"
OnClick="btnNext_Click" Text="Next"
Width="77px" CausesValidation="False" />