0

任何人都可以看到为什么这个表单以正常方式提交并且没有被 jQuery submit() 捕获,我在控制台中没有收到任何错误。

<script charset="utf-8">
$("#theform").submit(function(event) {  

    $.post('./index.php',{INPUT: $("#INPUT").val(),
                          TO_TYPE: $("#TO_TYPE").val(),
                          TO_V_BITRATE: $("#TO_V_BITRATE").val(),
                          TO_A_BITRATE: $("#TO_A_BITRATE").val()},
    function(data) {
        $('#divResult').replaceWith('<div id="divResult">'+ data.result +'<div>');
    });

    event.preventDefault();
    return false;
});
</script>

<h1>FFmpeg</h1>

<form id="theform" action="" method="POST">

  <p>Input file:
     <select size="1" id="INPUT" name="INPUT">
        <option value="demo.mp4">demo.mp4</option>
     </select>
  </p>

  <p>Convert To:
     <select size="1" id="TO_TYPE" name="TO_TYPE">
      <option value="AVI">AVI</option>
      <option selected value="MP4">MP4 (x264)</option>
      <option value="FLV">Flash</option>
     </select>

    Video Bitrate: 
    <select size="1" id="TO_V_BITRATE" name="TO_V_BITRATE">
     <option value="96">96</option>
     <option value="192">192</option>
     <option value="288">288</option>
     <option value="384">384</option>
     ...
    </select>

   Audio Bitrate: 
    <select size="1" id="TO_A_BITRATE" name="TO_A_BITRATE">
     <option value="96">96</option>
     <option value="192">192</option>
     <option value="288">288</option>
     <option value="384">384</option>
     ...
    </select>
  </p>
   <p><input type="submit" id="Submit" value="Convert"></p>
</form>
4

2 回答 2

2

尝试在表单之后或何时添加脚本$(document).ready(function(){do_something;});

于 2012-05-26T17:46:55.380 回答
2

你忘了设置event参数

$("#theform").submit(function(event) {
                                ^ ------ you missed it
....
});

你需要$包装器:

<script charset="utf-8" type="text/javascript">
  $(function() {

    $("#theform").submit(function(event) {  

      $.post('./index.php',{INPUT: $("#INPUT").val(),
                          TO_TYPE: $("#TO_TYPE").val(),
                          TO_V_BITRATE: $("#TO_V_BITRATE").val(),
                          TO_A_BITRATE: $("#TO_A_BITRATE").val()},
      function(data) {
        $('#divResult').replaceWith('<div id="divResult">'+ data.result +'<div>');
      });

      event.preventDefault();
     return false;
    });
  });
</script>
于 2012-05-26T17:38:56.203 回答