Javascript 为什么警报消息没有出现?

Javascript 为什么警报消息没有出现?,javascript,alert,Javascript,Alert,我有以下HTML代码: <form name="question_issue_form" id="question_issue_form" action="question_issue.php"> <table class="trnsction_details" width="100%" cellpadding="5"> <tbody> <tr> <td>&

我有以下HTML代码:

<form name="question_issue_form" id="question_issue_form" action="question_issue.php">
      <table class="trnsction_details" width="100%" cellpadding="5">
        <tbody>    
          <tr>
            <td></td>
            <td>
              <input type="checkbox" name = "que_issue[]" value = "Question is wrong" id ="chkQueWrong">Question is wrong</input>
            </td>
          </tr>
          <tr>
            <td></td>
            <td><input type="checkbox" name = "que_issue[]" value = "Answers are wrong" id ="chkAnsWrong">Answers are wrong</input></td> 
          </tr>
          <tr>
            <td></td>
            <td><input type="checkbox" name = "que_issue[]" value = "Question direction is incorrect" id ="chkDirIncorrect">Question direction is incorrecct</input></td>                
          </tr>
          <tr>
            <td></td>
            <td><input type="checkbox" name = "que_issue[]" value = "Other" id ="chkOther">Other</input></td>          
          </tr>
          <tr>
            <td></td>
            <td class="set_message" style="display:none;"><textarea name="que_issue_comment" rows="4" cols="25" maxlength="100"></textarea></td>      
          </tr>
          <tr>
            <td></td>
            <td><input type="submit" name="submit" value="Submit" id="report_question_issue"></td>
          </tr>
        </tbody>
      </table>
    </form>
单击submit按钮后,我会调用警报显示,但它不会显示。我不明白为什么会这样?以下是js Fiddle的链接供您参考;

$(XXX)这是一种jquery语法,但我看到您在纯JS环境中。
您应该使用js库吗?

问题在于
提交
操作在调用js之前重新加载页面。
要避免此问题,您可以通过以下方式之一进行更改:

第一次使用JS进入
操作
属性

<form name="question_issue_form" id="question_issue_form" action="javascript:alert('test')">
<form name="question_issue_form" id="question_issue_form" onsubmit="alert('test');" action="question_issue.php">
3rd在
submit
事件上使用jQuery

$('form#question_issue_form').submit(function() {
    alert('test');
    return false; //to avoid the reload
});
4th在
上使用jQuery单击提交按钮上的
事件

$('form#question_issue_form').click(function() {
    alert('test');
    return false; //to avoid the reload
});

您没有包括
JQuery
参考。而您缺少关闭


在您的代码括号中,最后没有正确关闭。这是必需的”)


请把你的JS代码。。。因为问题是关于JS的@乔德夫:我现在已经输入了JS代码。更正了代码。仅供参考,你错过了);最后。而且,您没有在您的JSFIDLE中链接Jquery库。这不是真的,javascript将在提交表单之前发生
return false
可以进入点击事件,我知道这不是“正确”答案,但我认为它提供了一个可能性列表。
$('form#question_issue_form').submit(function() {
    alert('test');
    return false; //to avoid the reload
});
$('form#question_issue_form').click(function() {
    alert('test');
    return false; //to avoid the reload
});
$(document).on('click', '#report_question_issue', function (e) {
    alert("Jumbo man");
});