use*_*403 5 jquery jquery-ui jquery-dialog
我希望能够按"ENTER"并让对话框执行与提交按钮相同的操作.
我在这里找到了一个类似的问题:在<Enter>上提交jQuery UI对话框.我在代码中添加了一些解决方案,并没有解决问题.
这是我到目前为止:
按钮:
<button id="myButton">Execute Tasks</button>
Run Code Online (Sandbox Code Playgroud)
对话框本身:
<div id='myDialog' title="New Task(s):">
<p>Enter the name of the tasks you wish to execute</p>
<form>
<label for="name">
<input type="text" name="name" id="name" />
</label>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
内部脚本标签:
$('#myButton').click( function() {
$( "#myDialog" ).dialog({
open: function(){
$("#myDialog").unbind('submit');
$("#myDialog").submit(function() {
$("#myDialog").parents('.ui-dialog').first().find('.ui-button').first().click();
return false;
});
},
buttons: {
"Run tasks": function() { .... },
"Cancel":function() { $(this).dialog("close"); };
},
});
});
Run Code Online (Sandbox Code Playgroud)
您可以在打开的对话框中绑定表单提交事件.在文本框中按Enter将自动触发表单提交.
您还可以在单击"运行任务"按钮时触发提交事件.
jsFiddle:http://jsfiddle.net/CodingDawg/dk7hT/
$('#myButton').click(function () {
$("#myDialog").dialog({
open: function () {
$(this).off('submit').on('submit', function () {
//Run tasks
//$(this).dialog('close'); //You can Close the dialog after running the tasks.
return false;
});
},
buttons: {
"Run tasks": function () {
$(this).find('form').submit();
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5286 次 |
| 最近记录: |