Help with preventdefault
I have a confirmation dialogue that pops after you hit ("#step0Next") on a form wizard. Currently it pops after you hit the button on the next step. I need it to pop when you hit the button on THAT step (step 1) not when it goes to step 2. How do I stop the default action of the button until the user click's "OK" in the dialogue?
$("#开发者_如何学Pythonstep0Next").live('click', function(event) {
event.preventDefault();
if($("#RT").is(":checked") && !$(".ex").is(':checked')) {
return confirm ('foo');
//alert("You have not selected any exchanges for which to receive real time market data from. If you continue, you will only receive real time data for market metrics and ten minute delayed data for everything else. Do you wish to continue?");
$(this).die('click');
}
});
confirm()
has no default action. Instead of returning it you need to prevent the default after checking the return value from it. (I'm not completely following your question, but I'm assuming you would want to continue after the user clicks OK ... not "stop the default action"?)
Remove event.preventDefault()
from where it is now and do:
if( ... long if statement ... ) {
if( confirm("Are you sure? Yadda Yadda") ) {
// User clicked OK
}
else {
// User clicked Cancel
event.preventDefault();
}
}
Of course if you really do want to prevent the default action of whatever was clicked even if the user clicked OK then leave the preventDefault call where it was. The code I provide will still tell you which button they clicked in the confirm dialog.
this didn't work. This did:
<script type="text/javascript">
$("#step0Next").live('click', function(event) {
$('#step1Prev').click(); //go back to step 1
if($('#RT').is(':checked') && !$('.ex').is(':checked')) {
if(!confirm("You have not selected any exchanges for which to receive real time market data from. If you continue, you will only receive real time data for market metrics and ten minute delayed data for everything else. Do you wish to continue?")) return;
$('#step0Next').die('click');
}
$(this).triggerHandler('click');
});
</script>
精彩评论