【发布时间】:2012-08-23 18:36:44
【问题描述】:
我有一个基于 JQUERY 的对话框,上面有一个“选择”。当我单击按钮时,我需要获取选择选项值。
这是我的 JavaScript 代码:
$( "#dialog-select" ).dialog({
resizable: true,
height:250,
width:450,
modal: true,
buttons: {
"Ok": function() {
var priority = $('#dialog-select')
.find('select[name="priority"]');
var priorityString = JSON.stringify(priority);
alert('priorityString : ' + priorityString);
$( this ).dialog( "close" );
return true;
},
Cancel: function() {
$( this ).dialog( "close" );
return false;
}
}
});
对话框的 HTML 是用 JavaScript 编写的。如下:
$('#dialog-select').html('<p><span>Please select</span></p>'+
'<table>'+
'<tbody>'+
'<tr>'+
'<td align="left"><font size="1" color="red">*</font></td>'+
'<td align="left"><label>New Priority</label></td>'+
'<td>'+
'<select name="priority">'+
'<option value = "default">Please select...</option>'+
'<option value = "h">High</option>'+
'<option value = "m">Medium</option>'+
'<option value = "l">Low</option>'+
'</select>'+
'</td>'+
'</tr>'+
'</tbody>'+
'</table>'+
'<br/>');
我上面做的没有用,请帮忙:)
【问题讨论】:
-
如果您需要比我下面的答案更具体的帮助,您应该创建一个 jsfiddle 供我们使用,这样会更容易。
标签: javascript jquery html jquery-dialog