Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery on(';focusout';)不会触发_Jquery - Fatal编程技术网

jQuery on(';focusout';)不会触发

jQuery on(';focusout';)不会触发,jquery,Jquery,我试图在编辑输入字段时设置自动保存。我知道db的任务是在每一个键上执行一个保存例程,所以我想我会在特定形式的输入的焦点上触发它。然而,它不会触发任何东西 我的jQuery: $('form#base_fields input').on('focusout', function(event) { alert('test'); }); 为了测试的目的,我简单地用一个警报替换了我的var创建和对ajax保存例程的调用,但它不会被触发。这是我的表格: <form method="PO

我试图在编辑输入字段时设置自动保存。我知道db的任务是在每一个键上执行一个保存例程,所以我想我会在特定形式的输入的焦点上触发它。然而,它不会触发任何东西

我的jQuery:

$('form#base_fields input').on('focusout', function(event) {

    alert('test');

});
为了测试的目的,我简单地用一个警报替换了我的var创建和对ajax保存例程的调用,但它不会被触发。这是我的表格:

<form method="POST" id="base_fields" enctype="multipart/form-data">
    <input name="formname" type="hidden" value="base_fields_article">
    <input name="formtable" type="hidden" value="tnt_treeview">
    <input name="nodeid" type="hidden" value="1005">
    <label for="articlenumber">article number</label>
    <div class="form-content">
        <input name="articlenumber" type="text" value="ART000001" class="form-control" required="" placeholder="articlenumber" tabindex="1">
    </div>
    <label for="articlename">article name</label>
    <div class="input-group">
        <input name="articlename" type="text" value="Random article number 1" class="form-control" required="" placeholder="articlename" tabindex="2">
        <div class="input-group-btn">
            <button type="button" class="btn btn-default" aria-expanded="false"><span class="fa fa-globe font-size-20"></span></button>
        </div>
    </div>
    <label for="shortdescription">Short description</label>
    <div class="input-group">
        <input name="shortdescription" type="text" value="Random article with some specifications number 1" class="form-control" placeholder="shortdescription" tabindex="3">
        <div class="input-group-btn">
            <button type="button" class="btn btn-default" aria-expanded="false"><span class="fa fa-globe font-size-20"></span></button>
        </div>
    </div>
    <label for="longdescription">Long description</label>
    <div class="input-group">
        <input name="longdescription" type="text" value="Random article complete marketing text. Can go up to a lot of items" class="form-control" placeholder="longdescription" tabindex="4">
        <div class="input-group-btn">
            <button type="button" class="btn btn-default" aria-expanded="false"><span class="fa fa-globe font-size-20"></span></button>
        </div>
    </div>
    <label for="EAN">EAN-13</label>
    <div class="form-content">
        <input name="EAN" type="text" min="13" max="13" class="form-control" placeholder="EAN" tabindex="5">
    </div>
</form>

物品编号
物品名称
简短描述
长描述
EAN-13
我不确定focusout是否像我想的那样工作,有人能把我推向正确的方向吗


编辑:jshiddle here:

在周围吐了几口唾沫之后,我结合了一些雨篷,得出以下结论

$(document).on('focusout','#base_fields input',function(){

    console.log('test');

}); 
有了一个用于测试目的的警报,我完全陷入了一个无休止的循环中,但通过document.on调用它,然后使用focusout和输入id作为向导,它成功了

参考


这可能会有所帮助,不过也有一些jQuery插件:代码中的警报对我有用。您是否在表单上应用了另一个插件以使其重新生成元素(如WYSIWYG编辑器)?根据jQuery docs focusout,这意味着单击远离输入,而不是将鼠标移离表单。有些人将此视为定时自动保存,也许你想在有人完全离开文档时自动保存?@NathanielFlick我的意思是输入错误。因此,我的jquery在输入中有它的目标。@AliSheikhpour在我的JS中甚至没有链接所见即所得编辑器。我确实有JStree在一旁运行,但我怀疑这会是一个问题。不是那样的。