h1.setAttribute('align','center')//添加属性
var value= h1.getAttribute('align')//读取属性值
JS代码让文字垂直居中的方法
水平居中方法: 将浏览器可视区的宽度(clientWidth) -减去 要居中元素本身的宽度(offsetWidth) /除以 2 +'px'
垂直居中方法: 将浏览器可视区的高度(clientHeight) -减去 要居中元素本身的高度(offsetHeight) /除以 2 +'px'
window.onload = function() {
var oMain = document.querySelector('#pop-main')
oMain.style.left = (document.documentElement.clientWidth - oMain.offsetWidth) / 2 +'px'
oMain.style.top = (document.documentElement.clientHeight - oMain.offsetHeight) / 2 +'px'
}
js代码
JS即Javascript,Javascript是一种由Netscape的LiveScript发展而来的脚本语言,主要目的是为了解决服务器终端语言,比如Perl,遗留的速度问题。
当时服务端需要对数据进行验证,由于网络速度相当缓慢,只有28.8kbps,验证步骤浪费的时间太多。于是Netscape的浏览器Navigator加入了Javascript,提供了数据验证的基本功能。
<!doctype html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
width:100px
height:100px
border:1px solid #000
text-align:left
}
</style>
</head>
<body>
<div id="div">52313</div>
<script>
(function(){
var o_div=document.getElementById("div")
o_div.style.textAlign="right"
})()
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)