JAVASCRIPT

操作屏幕元素

屏幕滚动

  • 窗口平滑滚动到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' %}')

 })
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行医冶文

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值