【问题标题】:Focusout jquery聚焦jQuery
【发布时间】:2021-12-02 19:27:03
【问题描述】:

当我执行此操作时,我得到了错误标签,因为我使用了带有表单字段共享点控件的时间选择器,所以

这是我的 jquery 验证代码

    $("input[id*='ffEnTime']").focusout(function () {
        if ($("input[id*='ffEnTime']").val().trim() == "") {
            $("span[id*='lblEntTime']").show();
            $("span[id*='lblEntTime']").text("Write Entry Time");
        }
        else {
            $("span[id*='lblEntTime']").hide();
        }
    }); 

以及我使用的时间选择器代码

$(document).ready(function () {
    //Start Validation at the after form loaded
    $("input[id*='ffPltNo']").attr("maxlength", "4");
    $("input[id*='ffIDNumber']").attr("maxlength", "10");
    $("input[id*='ffEnTime']").attr("autocomplete", "off");
    $("input[id*='ffEnTime']").attr("readOnly", "true");

    $("input[id*='ffEnTime']").timepicker({
        timeFormat: 'hh:mm p',
        minTime: '06:30:00', // 11:45:00 AM,
        maxHour: 24,
        maxMinutes: 30,
        startTime: new Date(0, 0, 0, 06, 0, 0), // 3:00:00 PM - noon
        interval: 30
    });

所以它看起来像这样 See pic

错误来了,因为当我单击任何时间进行选择时,它会首先关注然后验证将最终执行,它会选择时间,在这种情况下我必须再次选择让标签消失

有什么建议可以用更好的东西代替专注吗?

我尝试过更改,但对我不起作用。

【问题讨论】:

  • 你能用最少的 html 和代码提供一个jsfiddle.net 来重现问题吗?

标签: javascript c# jquery


【解决方案1】:

你试过了吗

 $("input[id*='ffEnTime']").on('input',function () {
//your validation function here
})

【讨论】:

    猜你喜欢
    • 2012-06-05
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多