//取出 ID为htmllid的元素
var obj = document.getElementById("htmllid");
//修改内容
obj .innerHTML = "内容";
//隐藏htmllid元素
var obj = document.getElementById("htmllid");
obj.style.display='none';
//删除htmllid元素
var obj = document.getElementById("htmllid");
obj.remove();
//在htmllid元素前添加元素
var obj = document.getElementById("htmllid");
var div = '<div id="newdiv">新增元素</div>';
obj.insertAdjacentHTML("beforebegin",div);
//枚举DIV标签元素
var div_ls = document.getElementsByTagName('div');
for(var i=0;i<div_ls.length;i++){
if(div_ls[i].getAttribute('id') == 'chars'){ //取当前索引元素ID
charts.push(div_ls[i]);
}
}
// textarea标签输入监控
// <textarea oninput="checkTxt(this)" ></textarea>
function checkTxt(obj) {
}
console.log('调试输出');
/**
*====================================================
*
* 全局键盘鼠标类
*
*====================================================
*/
window.onload=function(){
document.onmousedown=function(event) //鼠标按下事件
{
if(event.button==0){
//console.log("鼠标左键按下");
}else if(event.button==2){
//console.log("鼠标右键按下");
}else if(event.button==1){
//console.log("鼠标中键按下");
}else if(event.button==3){
//console.log("鼠标后退键按下");
}else if(event.button==4){
//console.log("鼠标前进键按下");
}else{
//console.log("鼠标摁下类型",event.button);
}
}
document.onmouseup=function(event) //鼠标弹起事件
{
//console.log("鼠标放开",);
}
document.onmousemove=function(event) //鼠标移动事件
{
//console.log("鼠标移动",event);
}
//console.log("页面加载完毕");
}
document.onkeydown = function (event) {
//console.log("键盘按下",event);
}
document.onkeyup = function (event) {
//console.log("键盘放开",event);
}
document.onkeypress = function (event) {
//console.log("键盘单机",event);
}
JS HTML前端操作相关函数
于 2023-04-18 09:27:43 首次发布