一、常用函数
// 延时3秒执行方法buttonIsCheck('finger')
setTimeout("buttonIsCheck('finger')","3000");
// 间隔6秒执行方法buttonIsCancel('finger')
setInterval("buttonIsCancel('finger')","6000");
// 滚动条 · 竖向移动index的长度
function setScollTo(index) {
window.scrollTo(0, index);
}
// 字符串截取
var str=“Hello happy world!”
str.slice(6); //从第6位开始截取到末尾 result:happy world!
str.slice(6,11); // 截取6到11位 result:happy
str.slice(-2); // 截取最后两位
二、JavaScript常用操作
// 重置class
document.getElementById(id).className = "btn-warning btn-3d-war";
// 修改属性
document.getElementById(id+"Span").setAttribute("data-feather", "check");
// textContent属性返回或设置当前元素中的文本内容
document.getElementById(id).textContent = "一体化采集 · 消息提示@";
三、fetch 异步访问后台服务示例
当前示例后台返回JSONString
/*
* 人像数据上传 · 把获取到的人像照片存储到服务器
* fileName:含后缀的文件名
* fileStr :人像采集程序返回的人像照片数据
* index:00-->二代证照;01-->正面照;02-->左侧照;03-->右侧照
*/
function uploadAfisImage(index, fileName, fileStr) {
var barcode = "53012568202307050099";
var psnId = 0;
fetch("/${sessionScope.project}/fileUpload/uploadPsnImage", {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
"psnId": psnId,
"psnNo": barcode,
"fileName": fileName,
"imageType" : index,
"fileStr": fileStr
})
}).then(function(response){
if(response.ok){
console.log("成功访问人像照片后台接收接口!");
response.json().then((data) => {
console.log(data); // 后台返回的json字符串
})
}
}).catch(function(error){
console.error('Error:', error);
console.log('There has been a problem with your fetch operation: ', error.message);
});
}
四、feather(图标)常用操作
1.引入依赖
<script type="text/javascript"
src="/${sessionScope.project}/feather/feather.min.js"></script>
<script type="text/javascript">
// feather显示图标
feather.replace({
'aria-hidden' : 'true'
});
</script>
2.动态更改feather图标
// 定位并修改属性
document.getElementById(id+"Span").setAttribute("data-feather", "x");
feather.replace(); //缺少此代码则图标不会进行更改