文章目录
操作屏幕元素
屏幕滚动
- 窗口平滑滚动到70网页高度
$('.down_btn').click(function () {
$('html , body').animate({scrollTop: document.body.scrollHeight * 0.7},'slow');
})
- 窗口平滑滚动到顶部
$('html , body').animate({scrollTop: 0},'slow');
获取元素
获取屏幕分辨率
网页可见区域宽:document.body.clientWidth
网页可见区域高:document.body.clientHeight
网页可见区域宽:document.body.offsetWidth (包括边线和滚动条的宽)
网页可见区域高:document.body.offsetHeight(包括边线的宽)
网页正文全文宽:document.body.scrollWidth
网页正文全文高:document.body.scrollHeight
网页被卷去的高:document.body.scrollTop
网页被卷去的左:document.body.scrollLeft
网页正文部分上:window.screenTop
网页正文部分左:window.screenLeft
屏幕分辨率的高:window.screen.height
屏幕分辨率的宽:window.screen.width
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidth
屏幕设置 window.screen.colorDepth 位彩色
屏幕设置 window.screen.deviceXDPI 像素/英寸
获取网页元素文本
textContent 方法可以获取到文本
var target_page = $('span.layui-laypage-curr').children()[1].textContent;
判断
判断字符串是否包含某个字符串
var str = "hello Tara";
if(str.indexOf("Tara") !== -1){ //-1表示不包含
alert("Hi,Tara");
}
//str.includes("")返回一个布尔值,值为true时表示包含
var str = "hello Tara";
if(str.includes("Tara")){
alert("Hi,Tara");
}
判断字典中是否包含某个key
if (!obj.data['children']){
}
// 意思是: 如果字典obj.data中不包含key: 'children'
多条件判断
if(num>0 && num<6){
alert("未及格");
}
判断undefined,null
- undefined
var exp = undefined;
if (typeof(exp) == "undefined")
{
alert("undefined");
}
- null
var exp = null;
if (!exp && typeof(exp)!=”undefined” && exp!=0)
{
alert(“is null”);
}
加载文件
在js中加载js
$('#point').click(function () {
$.getScript('{% static 'src/js/question_bank/get_autocomplete.js' %}')
})