解释此代码 jQuery
explain about this code jquery
我发现这个代码从扫描条形码中获取值
$(document).ready(function() {
$(document).focus();
var coba=[];
$(document).on('keypress',function(e){
coba.push(String.fromCharCode(e.which));
if (coba[coba.length-1]=="'r") {
console.log(coba.join(''));
simpan(coba.join(''));
coba = [];
};
});
});
任何人都可以解释一下吗?
首先,我建议您访问 jquery.com 并查看他们的 api 文档和/或他们的学习中心。
请参阅下面嵌入的评论。这不会专门处理条形码
//this is waiting until the browser has loaded the page and all the content
// the elements in the content are considered the DOM.
$(document).ready(function() {
//this sets the focus to the window, it acts as if you had clicked
// on a blank spot of the window.
$(document).focus();
//this sets up an empty array to hold characters that are being typed
var coba=[];
//this sets up the page so that, when a key is pressed it does something
//the anonymous function below is is executed when a key is pressed
$(document).on('keypress',function(e){
//adds the character that was pressed to the array
coba.push(String.fromCharCode(e.which));
//if the return key was pressed
if (coba[coba.length-1]=="'r") {
//print out the characters that were pressed on the browser console
console.log(coba.join(''));
//this passes the string that was typed to a function
// to a function named simpan -- can't tell you what that is
// because it isn't a browser function. Probably in a library
simpan(coba.join(''));
// empty out the array to wait for a new string to be typed
coba = [];
};
});
});
如果这与读取条形码有关,则可能发生的情况是连接到系统的条形码扫描仪就像键盘一样。simpan 函数可能由 javascript 库提供,甚至可能由硬件制造商提供。
祝你好运。
相关文章:
- 如何动态插入jquery代码
- 如何在php变量中嵌入JQuery代码
- 将 jQuery 代码添加到 Index.aspx 页面
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- Jquery:代码在rails中的页面加载时未执行
- 点击facebook像素跟踪注册(JS/JQUERY代码)
- 我的jquery代码不起作用.为什么?
- 将javascript代码转换为jquery代码时出错
- 在CodeIgniter视图中将Javascript或jQuery代码作为PHP文件编写可以吗
- 按键时停止jquery代码
- 在Grails中的gsp中执行jquery代码
- 这个jquery代码是如何工作的
- 如何在加载角度函数后运行jQuery代码
- 如何使用Javascript或jQuery代码调用mousemove
- 如何使用我的Jquery代码创建委托事件侦听器
- 为什么jQuery代码段在没有IFrame的情况下可以工作,而在有IFrame时却不能工作
- 将JQuery代码转换为等效的JavaScript代码
- JQuery代码语法问题?(“不允许内联控制结构”)
- 使用一个 jquery 代码关闭多个模态
- 如何简化动画jQuery代码