选择单选按钮以显示弹出窗口并保持选中状态
Selecting a radio button to display a popup and stay selected as well
在表单
中有如下两个单选按钮<input type="radio" name="advice" value="office" class="office">
<input type="radio" name="advice" value="phone">
当我选择office
单选按钮时,我想要显示一个弹出框。使用下面的脚本
$(function () {
$('.office').click(function (e) {
e.preventDefault();
var dialog = $('<p>Please be aware that our office is located at ABC.</p>').dialog({
buttons: {
"Close": function () {
dialog.dialog('close');
}
}
});
});
});
我遇到的问题是,虽然在选择单选按钮office
弹出出现,但单选按钮实际上没有被选中。DOT在单选按钮中保留在另一个单选按钮中,因此在提交表单时,我一直获得相同的单选按钮的值。
use change event by this当单选框改变时,对话框打开但是现在当你点击对话框打开但没有被选中因为它在change event
时没有打开$(function () {
$('.office').change(function (e) {
e.preventDefault();
var dialog = $('<p>Please be aware that our office is located at ABC.</p>').dialog({
buttons: {
"Close": function () {
dialog.dialog('close');
}
}
});
});
});
删除e.preventDefault()
, Here's a fiddle
我认为你应该用change
代替click
或者直接删除e.preventDefault();
$(function () {
$('.office').change(function (e) {
var dialog = $('<p>Please be aware that our office is located at ABC.</p>').dialog({
buttons: {
"Close": function () {
dialog.dialog('close');
}
}
});
});
});
只需使用jQuery .change()事件,无需担心。
$('.office').change(function (e) {
....
}
使用更改功能。点击在这种情况下不起作用。
检查提琴