前两个模板是基本需求,第三个就是其他需求了,例如有时候想给论文的“下载PDF”按钮换个位置,就要配合模板2,加个跳转,然后添加这么一个东东了!
function lamsALERT(){ alert("ALERTooooooooo");}
//方法1:onclick
document.getElementsByTagName("button")[0].onclick = lamsALERT
//方法2:onclick
document.getElementsByTagName("button")[0].onclick = function() { lamsALERT("lamsALERTNooooooooow!! "); }
//方法3:添加监听事件函数
document.getElementsByTagName("button")[0].addEventListener('click', lamsALERT)
//或
document.getElementsByTagName("button")[0].addEventListener('click', function(){ lamsALERT("lamsALERTNooooooooow!! ") })
//方法4:(需要在头部添加require jq库):
// @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
$(".ButtonClassName").click(() => {
lamsALERT("lamsALERTNooooooooow");
});
//较常用,为body绑定click事件,
//之前有个误区,以为只有button标签才能绑定click,
//原来是个标签都可以绑定,然后就可以click触发
document.getElementsByTagName("body")[0].addEventListener('click', function(){ judgeeCopyWithTime( document.getElementsByClassName("FATHER_CLASS_NAMECLASS_NAME")[0].children[0] ) })
document.getElementsByTagName("body")[0].addEventListener('click', function(){ judgeeCopyWithTime( document.getElementsByClassName("CLASS_NAME")[0] ) })
//格式2 方便直接复制用
setTimeout( function(){
document.getElementsByClassName("CLASS_NAME")[0].addEventListener('click', function(){
//看这里!直接更换函数就可以!
judgeeMODIFstyleByName(document.getElementsByClassName("CLASS_NAME")[0], "h", "500px")
})
} , 3000)
复制函数
function Copyy(valueCopy = '听说你想复制我') {
// var input = document.getElementsByTagName("button")[0];
// input.select();
// 为什么不行呢?因为button对象不是input对象,没有select函数
const input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', valueCopy );
input.select();
booll = document.execCommand("Copy");
console.log("success ????")
console.log(booll)
//用完就可以清理一下
document.body.removeChild(input);
}
//随便绑定一个按钮触发,该方式只能粗发一次
document.getElementsByTagName("button")[0].onclick = Copyy
方法2:使用库,具体可百度
// @require https://cdn.bootcss.com/clipboard.js/2.0.1/clipboard.min.js
// @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
//使用对比上面,相对简单一点
设计定时器,到点就疯狂触发事件,一般是预订场地用
setInterval(function(){
if(new Date().getHours()==12 &&new Date().getMinutes()==30 &&flag==false ){
document.getElementsByClassName("command_button_content")[2].click()
}
console.log("现在时间:")
console.log(new Date().getMinutes())
console.log(new Date().getSeconds())
},1000);
其他,打开、关闭、刷新网站
//其他应用点击打开网站
window.open("https://www.CSDN.net");
//指定大小打开网站
window.open(document.getElementsByTagName("a")[10].href,"",250,250)
//关闭窗口
window.close();
//不断刷新页面
window.setInterval( function(){ location.reload(); }, 2*1000);