你可以在jquery模式对话框中提交表单吗?

前端之家收集整理的这篇文章主要介绍了你可以在jquery模式对话框中提交表单吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在 jquery ui模式对话框中有一个表单,当我单击提交按钮时没有任何反应.有没有办法在jquery模式对话框中提交表单而无需在 javascript中编码按钮? @H_403_2@这是我的代码片段;

  1. <script>
  2. // increase the default animation speed to exaggerate the effect
  3.  
  4. $(function() {
  5. $( "#dialog" ).dialog({
  6. autoOpen: false,draggable: false,resizable: false,modal: true,});
  7.  
  8. $( "#opener" ).click(function() {
  9. $( "#dialog" ).dialog( "open" );
  10. return false;
  11. });
  12. });
  13.  
  14. function SetValues()
  15. {
  16. var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY ;
  17. document.getElementById('divCoord').innerText = s;
  18.  
  19. }
  20. </script>
  21.  
  22. <div id="dialog" title="new task">
  23. <form method="post" action="/projects/{{ project.slug }}/">
  24. <div class="form-row">
  25. <label class="required" for="title">task type</label>
  26. <select name="type">
  27. {% for TaskType in project.tasktype_set.all %}
  28. <option value="{{ TaskType.name }}">{{ TaskType.name }}</option>
  29. {% endfor %}
  30. </select>
  31. </div>
  32. <div id="buttons">
  33. <input type="submit" value="create"/>
  34. </div>
  35. </form>
  36. </div>
  37.  
  38. <button id="opener">new task</button>
@H_403_2@如果我删除“modal:true”,使对话非模态,它将提交.

解决方法

您可以在对话框中使用$.post()或$.ajax(),例如:
  1. $( "#dialog" ).dialog({
  2. autoOpen: false,buttons: {
  3. "Save": function() {
  4. var type = $("#type option:selected").val();
  5. $.post("/projects/{{project.slug}}/",{type:type},function(data) {
  6. alert(data);// ---> data is what you return from the server
  7. },'html');
  8. },"Close": function(){
  9. $(this).dialog('close');
  10. }
  11.  
  12. }
  13. });
@H_403_2@只需给你的select标签一个id ……就可以更容易地获取值.也摆脱了输入按钮,因为现在你将从对话框中保存按钮.

猜你在找的jQuery相关文章