【问题标题】:Jquery submit with additional function带有附加功能的 Jquery 提交
【发布时间】:2012-10-26 07:32:10
【问题描述】:

问题解决了。代码是正确的。它是Angularjs和Jquery之间的交互。如果你只使用 Jquery 就可以了

我正在尝试在我的表单提交中添加一个额外的检查方法。我正在使用Jquery提交功能here

下面是我的代码

HTML

<form id="upload_form" action="javascript:console.log('submitted');">
<table class="tablestyle">
    <tr>
        <td class="labelstyle" style="width:80px;">File</td>
        <td class="datastyle">
<input type="file" class="textinput" tabindex="7" id="file" name="file">
<input id="upload" name="upload" class="button" value="Upload" tabindex="8" type="submit"></td>
    </tr>   
</table>    
</form>

Javascript

$("#upload_form").submit(function() {
    console.log("checking");
});

但是,当我提交时,只有“javascript:console.log('submitted');”打印在我的控制台中。无法获取“console.log("checking");”上班。

谁知道是什么问题?

感谢任何帮助!谢谢。

【问题讨论】:

    标签: jquery forms submit


    【解决方案1】:

    您的代码没有错误。

    我创建了一个小提琴来证明你的代码:http://jsfiddle.net/tzjcA/

    打印所有日志消息

    $("#upload_form").submit(function() {
        console.log("checking");
    });​
    

    编辑

    按 F12,然后按“控制台”选项卡

    编辑 2

    精确的enctype method 并删除javascript:console.log('submitted');

    <form id="upload_form" enctype="multipart/form-data" method="post">
    <table class="tablestyle">
        <tr>
            <td class="labelstyle" style="width:80px;">File</td>
            <td class="datastyle">
    <input type="file" class="textinput" tabindex="7" id="file" name="file">
    <input id="upload" name="upload" class="button" value="Upload" tabindex="8" type="submit"></td>
        </tr>   
    </table>    
    </form>
    

    【讨论】:

    • 这很奇怪。它对我不起作用。会不会是Angularjs的原因?
    • 好的,你用的是哪个浏览器?
    【解决方案2】:

    那是因为你正在调用 colsole.log("submitted") 。打电话给你合适的 方法在起作用,它会起作用。

    <form id="upload_form" action="javascript:console.log('submitted');">
    

    【讨论】:

    • 这不是真的,检查我的答案
    • 你在哪里看到 colsole.log?
    • 按F12显示调试工具
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 2019-06-23
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多