我希望能够按下“ ENTER”并让对话框执行与提交按钮相同的操作。
我在这里发现了一个类似的问题:在<Enter>上提交jQuery UI对话框。我在代码中添加了一些解决方案,但没有解决问题的方法。
这是我到目前为止的内容:
按钮:
<button id="myButton">Execute Tasks</button>
对话框本身:
<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>
内部脚本标签:
$('#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"); };
},
});
});
您可以在对话框打开时绑定表单提交事件。在文本框中按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");
}
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句