为什么我的模糊事件处理程序不触发? [英] Why is my blur event handler not firing?

查看:82
本文介绍了为什么我的模糊事件处理程序不触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当五个金额"框中的任何一个输入金额时,我都有此jQuery更新总数:

I've got this jQuery to update the total when amounts are entered into any of the five "amount" boxes:

/* boxAmount1...boxAmount5 - when any of them change, update boxGrandTotal */
$(document).on("blur", '[id^="boxAmount"]', function (e) {
    alert('in the boxamount blur handler');
    var amount1 = $('[id$=boxAmount1]').val() != '' ? parseInt($('[id$=boxAmount1]').val()) : 0;
    // jakecigar's idea: add this just in case a user enters something other than a number: if ($.isNaN(amount1) amount1=0;
    var amount2 = $('[id$=boxAmount2]').val() != '' ? parseInt($('[id$=boxAmount2]').val()) : 0;
    var amount3 = $('[id$=boxAmount3]').val() != '' ? parseInt($('[id$=boxAmount3]').val()) : 0;
    var amount4 = $('[id$=boxAmount4]').val() != '' ? parseInt($('[id$=boxAmount4]').val()) : 0;
    var amount5 = $('[id$=boxAmount5]').val() != '' ? parseInt($('[id$=boxAmount5]').val()) : 0;
    var grandtotal = amount1 + amount2 + amount3 + amount4 + amount5;
    alert(grandtotal);
    $('[id$=boxGrandTotal]').val(grandtotal);
});

在Sµßhrånil∂的小提琴此处中,它的工作方式很花哨.但是对我来说,我从来没有看到我添加的警报(在boxamount模糊处理程序中").

In Sµßhrånil∂'s fiddle here, it works just dandy. But for me, I never see the alert I added ("in the boxamount blur handler").

起初,我认为这是因为我未能为五个boxAmount输入文本分配ID-的确,我忘记了这一点.但是,即使添加了ID,也是如此:

At first I thought that it was because I had failed to assign IDs to the five boxAmount input texts - it was true that I had forgotten that. But even after adding the IDs, like so:

boxAmount1 = new TextBox()
{
    CssClass = "dplatypus-webform-field-input",
    ID = "boxAmount1",
    Width = TEXTBOX_WIDTH
};
cellColAmount1.Controls.Add(boxAmount1);

...未达到处理程序.

...the handler is not reached.

从某种意义上讲,现在大多数"boxAmount"是动态创建的,这是事实-用户可以有条件地使它们可见.但是,上面显示的第一个("boxAmount1")始终可见,因此应始终为可查找".但是,即使在退出/模糊该特定输入文本时,我也看不到在boxamount模糊处理程序中".

Now it is a fact that most of the "boxAmount"s are created dynamically, in a sense - they are made visible conditionally by the user. However, that first one, shown above ("boxAmount1") is always visible, and so should always be "findable." But even on exiting/blurring out of that particular input text, I do not see "in the boxamount blur handler".

为什么不呢?如何在此处理程序下点火,以使其响应退出/模糊事件?

Why not? How can I light a fire under this handler to make it responsive to the exit/blur event?

"boxAmount1"确实出现在查看源代码"中:

"boxAmount1" does indeed appear in the "View Source":

input name="ctl00$ctl24$g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33$ctl00$boxAmount1" type="text" id="ctl00_ctl24_g_5f3fedca_19f7_4bc3_b84e_efbef0c48a33_ctl00_boxAmount1" class="finaff-webform-field-input" style="width:88px;" />

  • ,实际上,其他所有对象也都这样做(boxAmount2 ... boxAmount5).
  • 推荐答案

    在id上触发模糊事件,请尝试对类别为finaff-webform-field-input输入模糊进行尝试.因为同一ID不能在同一页面上多次出现:

    Firing blur event on id try it with the input blur with class finaff-webform-field-input. because same id could not be multiple time on the same page :

    这是班级模糊事件

     /* boxAmount1...boxAmount5 - when any of them change, update boxGrandTotal */
        $(document).on("blur", '.dplatypus-webform-field-input', function (e) {
            alert('in the boxamount blur handler');
            var amount1 = $('#boxAmount1').val() != '' ? parseInt($('#boxAmount1').val()) : 0;
            // jakecigar's idea: add this just in case a user enters something other than a number: if ($.isNaN(amount1) amount1=0;
            var amount2 = $('#boxAmount2').val() != '' ? parseInt($('#boxAmount2').val()) : 0;
            var amount3 = $('#boxAmount3').val() != '' ? parseInt($('#boxAmount3').val()) : 0;
            var amount4 = $('#boxAmount4').val() != '' ? parseInt($('#boxAmount4').val()) : 0;
            var amount5 = $('#boxAmount5').val() != '' ? parseInt($('#boxAmount5').val()) : 0;
            var grandtotal = amount1 + amount2 + amount3 + amount4 + amount5;
            alert(grandtotal);
            $('#boxGrandTotal').val(grandtotal);
        });
    

    这篇关于为什么我的模糊事件处理程序不触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆