input输入框必须指定最大长度
新建打印窗口,打印不全的问题
printWin = window.open("", "newwin", "");
//printWin.document.write(printHtml);
//printWin.document.close();
printWin.document.body.innerHTML= printHtml;
printWin.window.print();
printWin.close();
jQuery选择器中含有特殊字符的问题
用两个/转义
1
var $id_a = $('#id.a');//jQuery对象,实际上是没取到元素的
2
var $id_b = $('#id#b');//jQuery对象,实际上是没取到元素的
3 alert($id_a.length);//输出0
4 alert($id_b.length);//输出0
5 var $id_right_a = $('#id\\.a');//jQuery对象,对特殊字符,我们转义一下
6 var $id_right_b = $('#id\\#b');//jQuery对象,对特殊字符,我们转义一下
7 alert( $id_right_a.html() );//正确输出"aa"
8 alert($id_right_b.html() );//正确输出"bb"
https://blog.csdn.net/heganlin/article/details/53378988
子元素超过父容器限制
- 在父容器上设置overflow
执行后开始定时执行
var i=0;
function run() {
let showNums = new Promise((resolve, reject) => {
console.log(i)
i++;
resolve()
})
setTimeout(function () {
showNums.then(() => {
run()
})
}, 6000);
}
run()
避免正则表达式攻击
- 编写高性能的正则
判断函数体是不是为空的正则
- 用eval函数
- 正则
function cmdDowntext\(\)\{[\s\S]*[a-z]+[\s\S]*\}
同名函数调用问题
- 在同一文件下
var hereOrThere;
hereOrThere = function() {
return 'here';
};
function hereOrThere() {
return 'there';
}
console.log(hereOrThere()); //输出here
- 在不同文件下
// demo2.js
var hereOrThere;
hereOrThere = function() {
return 'here';
};
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="demo2.js" type="text/javascript"></script>
</head>
<body>
<button type="button" onclick="run()">Click Me!</button>
</body>
<script>
function hereOrThere() {
return 'there';
}
console.log(hereOrThere()); // 输出there
</script>
</html>
原因:js解释器遇到script标签会分开解释,可以简单理解为不同script标签有不同的作用域
关键词: EC VO AO
jqeury获取子元素
$("#divId").children("div").get(0) //获取dom对象
$($("#divId").children("div").get(0)) //获取jquery对象
js/jquery获取不到页面元素 需要点击一下才能找到
一开始想到可能是未来元素的原因,尝试过后发现并没有用处。
后来想到在form表单提交的时候如果有两层form嵌套,就会出现提交不了的现象。那会不会iframe嵌套也会出现这个问题呢?
当只使用一层iframe层时,也是可以正常获取元素的。那么两层的时候为什么会不行了呢?
查阅资料得知,当我们去获取元素时,js会默认在外层iframe中寻找元素,如果我们要寻找里层iframe的元素,必须要切换到指定iframe层中。
https://blog.csdn.net/tutian2000/article/details/79273895
jQuery获取iframe
$(".layui-layer-content",window.parent.document).children("iframe");
打印高度显示不全的问题
- Make sure all print floats are: float none;
- Make sure your body is overflow-y: visible;
- Make sure all your contents for print have display: block;
el-form校验 Promise 一直pending的问题
- 是因为validate校验函数没有调callback的原因
- 一定要调用callback !!!!
f12调试进入vm+数字开头的文件确定代码位置
https://stackoverflow.com/questions/17367560/chrome-development-tool-vm-file-from-javascript
Whenever you load HTML content through AJAX, and that content contains script tags, the script will be evaluated using eval() and recognized by Chrome’s Sources view as a new file beginning with ‘VM’. You can always go to the Network tab, find the AJAX request, and view the HTML response in its entirety, including your script.
- 通过network查看请求的js
IE浏览器img标签onload不生效问题
- 将onload放到src前面