我使用以下jQuery代码来检测条形码扫描并将条形码数据放入子页面上的文本框中。现在,此代码位于子页面中,它按预期工作:
export default combineReducers({
route,
posts: navAwarable(posts)
});
我需要将此jQuery移动到我的母版页,但我无法弄清楚如何从母版页引用子页面上的txtBarcode和btnRefresh控件。任何人都可以给我一些onComplete回调函数的示例代码,它允许我从母版页填充子页面上的控件吗?
<script type="text/javascript" src="Scripts/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.scannerdetection.js"></script>
<script type="text/javascript">
$(document).scannerDetection({
minLength: 5, // override the default minLength of 6 since barrel numbers are 5 digits - otherwise onError is triggered
timeBeforeScanTest: 200, // wait for the next character for upto 200ms
endChar: [13], // be sure the scan is complete if key 13 (enter) is detected
avgTimeByChar: 40, // it's not a barcode if a character takes longer than 40ms
ignoreIfFocusOn: 'input', // turn off scanner detection if an input has focus
onComplete: function (barcode, qty) {
$('#<%= txtBarcode.ClientID%>').val(barcode);
$('#<%= btnRefresh.ClientID%>').click();
},// main callback function
scanButtonKeyCode: 116, // the hardware scan button acts as key 116 (F5)
scanButtonLongPressThreshold: 5, // assume a long press if 5 or more events come in sequence
onError: function (string) { alert('Error ' + string); }
});
</script>
谢谢!
答案 0 :(得分:2)
像以前一样将该方法放在子页面中,但命名为,如下所示:
...
onComplete: detectionCompleted
...
现在,只需在母版页中使用该名称,如下所示:
txtBarcode
或者,你可以依靠css-class。只需为btnRefresh
和txtBarcode
使用唯一的css类名,然后像这样使用jQuery:
在子页面上,添加css级btnRefresh
和<asp:TextBox id="txtBarcode" class="barcode-textbox" />
<asp:Button id="btnRefresh" class="barcode-btn" />
控件:
onComplete: function (barcode, qty) {
$('.barcode-textbox').val(barcode);
$('.barcode-btn').click();
}
现在,请在主页面中调用:
vendor