js常用方法
2021-07-12 本文已影响0人
zlf_j
1、点击事件:
let submitBtn = document.getElementById('submitBtn');
submitBtn.onclick = function() {
console.log('111')
}
2、获取input的值
var G=document.getElementById('value').value
3、模糊搜索
let keyword = '内容' // 需要搜索的关键字
let originalArr = [{name: '内容', age: '14'},{name: '内容2', age: '34'}, {name: '内容3', age: '18'}] // 原始数组
let teacherList = this.originalArr.filter(array => array.name.match(keyword)); // 关键代码
console.log(teacherList) // 匹配筛选之后的目标数组
4、url作为参数
// 原url
var url = '/picture/detail?clinicId=7&patientId=222222'
// encodeURIComponent
var url2 = encodeURIComponent(url)
// encodeURIComponent解析后的url
var url3 = decodeURIComponent(url2)
http://www.5ixuexiwang.com/m/view.php?aid=2113
https://blog.csdn.net/li2327234939/article/details/53675211
5、判断undefined类型
var str = undefined
if (typeof(str) == 'undefined') {
console.log('类型是undefined')
}