[原创js]指定DOM中添加字符串函数写了个简单的的⼩函数。
===============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>⽆标题⽂档</title>
</head>
<body>
<table border="1">
<tbody>
<tr>
<td id="cell1">沈冥峰</td>
<td id="cell2">没我</td>
<td id="cell3">帅</td>
</tr>
</tbody>
</table>
<br /><br />
<hr />
<input type="button" id="btn1" value="在前⾯加2个空格" />
<input type="button" id="btn2" value="在后⾯加1个空格" />
<script type="text/javascript">
function addEmpty(oDomId,oCount,ofront){
var dom = ElementById(oDomId);
字符串函数模拟注册var count = oCount || 1;
var frontFlag = ofront || false;
var str = " ";
var addStr = "";
for(var i=0;i<count;i++){
addStr = addStr + str;
}
if(frontFlag){
dom.innerHTML = addStr + dom.innerHTML;
} else {
dom.innerHTML = dom.innerHTML + addStr;
}
}
var btn1 = ElementById("btn1");
var btn2 = ElementById("btn2");
addEmpty("cell1",2,true);
};
addEmpty("cell2");
};
</script>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论