我正在使用 jQuery Mobile。我有一个切换按钮,当用户单击时,我需要启动一个确认对话框。
HTML
<div data-role="fieldcontain">
<div class='ui-grid-a' >
<div class='ui-block-a'>
<h4 rel='tooltip' title='Feature that automatically solves other values as you type in inputs' style='color:#cc0000;'>Auto-Solve</h4>
</div>
<div class='ui-block-b'>
<select name="togSwitch" id="autosolve" data-theme="" data-role="slider" data-mini="true">
<option value="off">Off</option>
<option selected value="on">On</option>
</select>
</div>
</div>
</div>
jQuery
$(document).ready(function() {
$('#autosolve').toggle(function() {
var answer = confirm('This will erase all current values. Are you sure you want to continue?');
if (answer === false) {return;} else {reset();}
}, function() {
var answer = confirm('This will erase all current values. Are you sure you want to continue?');
if (answer === false) {return;} else {reset();}
});
});
我也试过做一个标准的点击功能,但没有奏效:
$('#autosolve').click(function() {
var answer = confirm('This will erase all current values. Are you sure you want to continue?');
if (answer === false) {
return;
} else {
reset();
}
});
我也尝试过 .change() 但它会启动 onload,并且它还在我的切换开关下方显示一个小选择框,这很奇怪。
一旦用户单击切换开关,有谁知道如何正确启动确认对话框?在切换开关改变之前