本文实例为大家简单分享javascript、jquery实用demo,供大家参考,具体内容如下
javascript判断H5页面离开
function onbeforeunloadFn(){
console.log('离开页面');
//...code
}
function showonbeforeunload(flags){
if(flags){
document.body.onbeforeunload = onbeforeunloadFn;
}else{
document.body.onbeforeunload = null;
}
}
$(function(){
showonbeforeunload(true);
})
jq判断img标签图片地址是否已经加载完毕
imgStatus = 0;
$("img").each(function(){
if(this.complete){
imgStatus++;
}
});
iframe获取内容-和设置
if($(".ad_show iframe").size() > 0 ){
$(".ad_show iframe").attr("id","iframead");
var iframebox = document.getElementById("iframead").contentWindow;
iframebox.document.body.innerText = "1234";
}
javascript获取浏览器上一页的url
var beforeUrl = document.referrer;
关于头疼的移动端点击冒泡事件
....
简单倒计时功能
jQuery的节点操作
jQuery.parent(expr) jQuery.parents(expr) jQuery.children(expr) jQuery.contents()
js中if判断语句中的in语法
if(1 == 1){
alert("1等于1");
}else{
alert("1不等于1");
}
if(1 in window){
alert("window包含1");
}else{
alert("window不包含1");
}
js的try-catch
try{
foo.bar();
}catch(e){
console.log(e.name + ":" + e.message);
}
try{
throw new Error("Whoops!");
}catch(e){
console.log(e.name + ":" + e.message);
}
try {
coo.bar();//捕获异常,ReferenceError:引用无效的引用
}catch(e){
console.log(e instanceof evalError);
console.log(e instanceof RangeError);
if(e instanceof evalError){
console.log(e.name + ":" + e.message);
}else if(e instanceof RangeError){
console.log(e.name + ":" + e.message);
}else if(e instanceof ReferenceError){
console.log(e.name + ":" + e.message);
}
}
js中typeof和instanceof区别
try {
throw new myBlur(); // 抛出当前对象
}catch(e){
console.log(typeof(e.a)); //返回function类型
if(e.a instanceof Function){//instanceof用于判断一个变量是否某个对象的实例,true
console.log("是一个function方法");
e.a();//执行这个方法,输出"失去焦点"
}else{
console.log("不是一个function方法");
}
}
function myBlur(){
this.a = function(){
console.log("失去焦点");
};
}
if(typeof(param) == "object"){
alert("该参数等于object类型");
}else{
alert("该参数不等于object类型");
}
console.log(Object instanceof Object);//true
console.log(Function instanceof Function);//true
console.log(Number instanceof Number);//false
console.log(String instanceof String);//false
console.log(Function instanceof Object);//true
console.log(Foo instanceof Function);//true
console.log(Foo instanceof Foo);//false
HTML5缓存sessionStorage
sessionStorage.getItem(key)//获取指定key本地存储的值 sessionStorage.setItem(key,value)//将value存储到key字段 sessionStorage.removeItem(key)//删除指定key本地存储的值 sessionStorage.length//sessionStorage的项目数
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



