js控制div内的字数 急!!!!!!!!
<divname="field">fffffffffffffffffffffffffffffffffffff</div><divname="field">ssssssss...
<div name="field">fffffffffffffffffffffffffffffffffffff</div>
<div name="field">ssssssssssssssssssssssss</div>
。。。。。。。。。。。。。。。。。。。。。。。。。
怎么用脚本同时控制多个div内的字数在10个以内,每个div必须name值相同 展开
<div name="field">ssssssssssssssssssssssss</div>
。。。。。。。。。。。。。。。。。。。。。。。。。
怎么用脚本同时控制多个div内的字数在10个以内,每个div必须name值相同 展开
展开全部
<style>
li{border:red solid 1px; width:30px; height:150px; margin-left:5px; float:left;}
td{ padding:0 5px;}
.spa{ width:100%;border:blue solid 1px; float:left}
input{ width:40px;}
.red{ background:red}
.white{ background:white}
.blue{ background:blue}
</style>
下面是name属性为field的div
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
下面是name属性的div
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
</table>
<input id="getTime" value="good" type="button" size="" style="width:200px" />
<script>
var bm=document.getElementById('getTime');
bm.onclick=function(){
var div = document.getElementsByTagName('div');
for(var i=0;i<div.length;i++){
if(div[i].name=='field')div[i].innerHTML=div[i].innerHTML.replace(/(^.{10}).*/g,'$1')
}
}
</script>
li{border:red solid 1px; width:30px; height:150px; margin-left:5px; float:left;}
td{ padding:0 5px;}
.spa{ width:100%;border:blue solid 1px; float:left}
input{ width:40px;}
.red{ background:red}
.white{ background:white}
.blue{ background:blue}
</style>
下面是name属性为field的div
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
<div name="field">123456789abcd</div>
下面是name属性的div
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
<div name="">123456789abcd</div>
</table>
<input id="getTime" value="good" type="button" size="" style="width:200px" />
<script>
var bm=document.getElementById('getTime');
bm.onclick=function(){
var div = document.getElementsByTagName('div');
for(var i=0;i<div.length;i++){
if(div[i].name=='field')div[i].innerHTML=div[i].innerHTML.replace(/(^.{10}).*/g,'$1')
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询