1

所以我有两个文本框,都被条形码扫描仪使用。Textbox1 是材料,Textbox2 是进度。我想在 TB2 扫描“F4”并聚焦 Textbox1 时清除 TB1 和 TB2。

我想不通,所以我来找你堆。

谢谢你的帮助。

4

1 回答 1

1

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. But, it's possible with JavaScript. Consider the following 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.

This could technically be hacked with the ASP.NET post back model, but it wouldn't be pretty. You'd have to use the same JavaScript event to actually force a post back:

$("#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.

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. 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. As you can see, it just gets uglier.

于 2013-11-06T16:02:37.710 回答