『壹』 js使用div内容居中
1、准备好一个空的html结构的文档。

『贰』 如何用js给html表单设置style
首先,把CSS和JS标签style属性对照表了解了:    
CSS 和 javaScript 标签 style 属性对照表:   
盒子标签和属性对照   
CSS语法(不区分大小写)       JavaScript语法(区分大小写)   
border                                     border   
border-bottom                       borderBottom   
border-bottom-color              borderBottomColor   
border-bottom-style               borderBottomStyle   
border-bottom-width             borderBottomWidth   
border-color                            borderColor   
border-left                               borderLeft   
border-left-color                      borderLeftColor   
border-left-style                       borderLeftStyle   
border-left-width                     borderLeftWidth   
border-right                             borderRight   
border-right-color                   borderRightColor   
border-right-style                    borderRightStyle   
border-right-width                  borderRightWidth   
border-style                             borderStyle   
border-top                               borderTop   
border-top-color                     borderTopColor   
border-top-style                      borderTopStyle   
border-top-width                    borderTopWidth   
border-width                           borderWidth   
clear               clear   
float               floatStyle   
margin              margin   
margin-bottom           marginBottom   
margin-left         marginLeft   
margin-right            marginRight   
margin-top          marginTop   
padding             padding   
padding-bottom          paddingBottom   
padding-left            paddingLeft   
padding-right           paddingRight   
padding-top         paddingTop   
  
颜色和背景标签和属性对照       
CSS 语法(不区分大小写)   JavaScript 语法(区分大小写)   
background          background   
background-attachment       backgroundAttachment   
background-color        backgroundColor   
background-image        backgroundImage   
background-position     backgroundPosition   
background-repeat       backgroundRepeat   
color               color   
    
样式标签和属性对照   
CSS语法(不区分大小写)       JavaScript 语法(区分大小写)   
display             display   
list-style-type         listStyleType   
list-style-image        listStyleImage   
list-style-position     listStylePosition   
list-style          listStyle   
white-space         whiteSpace   
    
文字样式标签和属性对照   
CSS 语法(不区分大小写)   JavaScript 语法(区分大小写)   
font                font   
font-family         fontFamily   
font-size           fontSize   
font-style          fontStyle   
font-variant            fontVariant   
font-weight         fontWeight   
    
文本标签和属性对照   
CSS 语法(不区分大小写)   JavaScript 语法(区分大小写)   
letter-spacing          letterSpacing   
line-break          lineBreak   
line-height         lineHeight   
text-align          textAlign   
text-decoration         textDecoration   
text-indent         textIndent   
text-justify            textJustify   
text-transform          textTransform   
vertical-align          verticalAlign   
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<HTML>  
 <HEAD>  
  <TITLE> New Document </TITLE>  
 </HEAD>  
<script language="javascript">  
function validate(){  
      if (document.all("name").value == ""){  
            document.all("name").style["borderColor"]="red";//就是这里  
            return;  
        }  
}  
</script>  
 <BODY>  
  <input type="text" name="name" >  
 </BODY>  
</HTML>
『叁』 在JS中如何给text-align赋值
HTML DOM 允许 JavaScript 改变 HTML 元素的样式,设置text-align样式的代码为:
obj.style.textAlign="left/right/center";
实例演示如下:
1、HTML结构
<divid="test">示例文字</div>
<inputtype="button"value="左对齐"onclick="fun1()">
<inputtype="button"value="居中"onclick="fun2()">
<inputtype="button"value="右对齐"onclick="fun3()">
2、javascript代码
functionfun1(){
	document.getElementById("test").style.textAlign="left";
}
functionfun2(){
	document.getElementById("test").style.textAlign="center";
}
functionfun3(){
	document.getElementById("test").style.textAlign="right";
}3、效果演示

『肆』 JavaScript 如何使文本两端对齐
居中?
对象容器.style.textalign="center"
或者left/right
『伍』 js控制文本框内容右对齐
为什么要用JS控制呢?直接<input type="text" id="txt" style="text-align:right;" />不就可以了么?
『陆』 怎样用JS设置text中文本的对齐方式
<!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>
『柒』 怎么让文字垂直居中,js代码
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 表格动态内容居中显示
在外面给td加个样式"text-align: center;"
或者直接填进去document.writeln('<td style="text-align:center;">sssss</td>');