offsetHeight 正则表达式验证格式
获取Div 的height width等属性
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <style> #a { width:20%; height:50px; background-color:yellow; margin-left:2%; } </style> </head> <body> <form id="form1" runat="server"> <div id="a"></div> <asp:Button ID="Button1" runat="server" Text="Button" /> </form> </body> </html> <script> document.getElementById("Button1").onclick = function () { var a = document.getElementById("a"); alert(a.offsetHeight);//无论是在CSS里面还是Style里面都能取到值 alert(a.style.width);//只能取到Style里面的值,不能取到CSS里面的值 } </script>
正则表达式验证格式
<script> if(/^正则表达式$/.test(a.innerText))//注意(.test) { alert("正确"); } else { alert("错误"); } </script>