『壹』 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>');