导航:首页 > 编程语言 > js批量设置

js批量设置

发布时间:2025-01-24 18:02:37

『壹』 js中如何为许多DOM对象批量添加事件

window.onload=function(){
vardivs=document.getElementsByTagName("div");
for(vari=0;i<divs.length;i++){
if(!!divs[i].id.match(/hover/)){
divs[i].onclick=function(){console.info("spiderman!");};
}
}
}

『贰』 使用js如何给标签的class值批量赋值

添加多个class 其实可以先从添加一个class然后对其进行封装

好的我废话就不多说了下面给出一份演示

<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Title</title>
<style>
.asdasd{
width:100px;
height:100px;
background-color:#cccccc;
}
.hello{
background-color:#00AEEF;
}
</style>
</head>
<body>
<divclass="asdasd"id="demo">

</div>
<script>
//清楚空格
functiontrim(str,t){
if(typeoft=="undefined"){
t="lr";
}
switch(t){
case"l":{
returnstr.replace(/(^s*)/g,"");
}
case"r":{
returnstr.replace(/(s*$)/g,"");
}
case"lr":{
returnstr.replace(/(^s*)|(s*$)/g,"");
}
}

}
//增加Class
functionaddClass(ele,cls){
if(!ele.getAttribute)return;
varallClass=[];
cls=trim(cls);
if(ele.getAttribute("class")==null){}else{
allClass=ele.getAttribute("class").split("");
}
if(!inArr(allClass,cls)){
allClass.push(cls);
ele.setAttribute("class",allClass.join(""));
}
}
//循环
functioneach(arr,f){
if(!arr.length)returnconsole.log("error:arrayisnotlength");
for(vari=0;i<arr.length;i++){
f.call(arr[i],i,arr[i]);
}
}
//是否在数组里面其实可以通过indexof判断但是indexof是匹配了数据类型的
functioninArr(arr,v){
if(!arr.length)returnfalse;
for(vari=0;i<arr.length;i++){
if(v==arr[i]){returntrue;}
}
returnfalse;
}
//增加多个Class
functionaddClassArr(ele,arr){
each(arr,function(){
addClass(ele,this);
})
}
addClassArr(document.getElementById("demo"),["a1","hello","world"])
</script>
</body>
</html>

可以看到 如果没有执行addClassArr这个函数显示的效果的这样的

『叁』 我想用js或者jquery 批量替换一个字符串

varstr='<divclass="demo1"style="height:auto;min-height:0px;width:1500px;color:red;“>内容1</div>'+
'<divclass="demo1"style="height:auto;min-height:0px;width:1500px;color:red;“>内容2</div>'+
<divclass="demo2"style="height:auto;min-height:0px;width:1500px;color:red;“>内容3</div>'
str=str.replace(/width:s*(d)+/g,'width:1000');
这样后str就是替内换后的结果容

『肆』 批量修改JS文件名称.

for i=1089914 to 1090026
Name cstr(i) & ".js" as format(i-1089913,"000") & ".txt"
next

阅读全文

与js批量设置相关的资料

热点内容
捕鱼达人历史版本 浏览:73
mp4视频文件解密软件 浏览:62
多轴编程哪个软件最方便 浏览:27
老平板哪个是显示屏数据线插座 浏览:849
5sing上传音频文件格式 浏览:171
win10输入文件鼠标右键异常 浏览:634
听幼儿故事用什么app 浏览:514
iphone修改音频文件名 浏览:53
国家气象站点数据在哪里下载 浏览:342
网络设置的网站 浏览:914
手机测量放样怎么导数据和线型 浏览:648
企业展示型网站源码 浏览:781
易花花app哪里下载 浏览:323
外国程序员职业生涯长 浏览:709
看理想app怎么注销账号 浏览:545
数控铣床加工手工编程的步骤有哪些 浏览:411
uc浏览器为什么很多网站进不了 浏览:513
西部数据移动硬盘怎么 浏览:645
批处理修改子目录文件名命令 浏览:405
文件损坏怎么删除 浏览:977

友情链接