简体   繁体   English

TextBox验证的离开事件

[英]Leave event of the TextBox Validation

So i have Two textboxes, both being used by Barcode scanner. 所以我有两个文本框,都被条形码扫描仪使用。 Textbox1 is material and Textbox2 is progress. Textbox1是重要的,Textbox2是进度。 I would like to clear TB1 and TB2 when TB2 scans "F4" and focus Textbox1. 当TB2扫描“ F4”并聚焦Textbox1时,我想清除TB1和TB2。

I couldn't figure it out so i came to you stack. 我想不通,所以我来找你。

Thanks for any help. 谢谢你的帮助。

So capturing bar code scans is tricky. 因此,捕获条形码扫描非常棘手。 The event model is the problem. 事件模型就是问题所在。 To make matters worse, you're using ASP.NET so it's going to be even harder. 更糟糕的是,您正在使用ASP.NET,因此它将变得更加困难。 But, it's possible with JavaScript. 但是,使用JavaScript是可能的。 Consider the following jQuery: 考虑以下jQuery:

$("#textBox2").on('keyup', function(event) {
    o = $(this);
    if (o.val() === 'F4') {
        // post the values back to the server via AJAX

        // clear the text boxes
        $("#textBox1").val('');
        o.val('');

        // focus the first text box
        $('#textBox1").focus();
    }
});

where #textBox2 is the id attribute of the input element you want to interrogate and #textBox1 is the id attribute of the input element that houses material value. 其中#textBox2是要查询的input元素的id属性,而#textBox1是容纳材料值的input元素的id属性。

This could technically be hacked with the ASP.NET post back model, but it wouldn't be pretty. 技术上讲,这可以用ASP.NET回发模型来破解,但不是很漂亮。 You'd have to use the same JavaScript event to actually force a post back: 您必须使用相同的JavaScript事件来实际强制回发:

$("#textBox2").on('keyup', function(event) {
    o = $(this);
    if (o.val() === 'F4') {
        $('#formName').submit();
    }
});

where #formName is the id attribute of the form element you're inside of. 其中#formName是您位于其中的form元素的id属性。

And then server-side you'd have to consume the TextChanged event of the second text box and check its value to know you ought to clear the values of both. 然后在服务器端,您必须使用第二个文本框的TextChanged事件,并检查其值以知道您应该清除这两个值。 It's just a little fickle. 只是有些善变。

Finally, using this post back model, you'd have to register some client startup script to set the focus to the first text box because you'll need some JavaScript to do that. 最后,使用此回发模型,您将必须注册一些客户端启动脚本以将焦点设置到第一个文本框,因为您需要一些JavaScript才能执行此操作。 As you can see, it just gets uglier. 如您所见,它变得更难看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM