JavaScript常用知识

来源:互联网 发布:结构体数组赋值 编辑:程序博客网 时间:2024/03/29 19:54

///javascript中去掉两端的空格
<script type="text/javascript">
 function test()
 {
  var str="     中华人民共和国     "; 
  alert(str.length);

  str=str.replace(/(^/s*)|(/s*$)/g,   "");
  alert(str.length); 
 }
</script>
<body onload="test()">

<%--显示层(固定显示字符长度)--%>
   <div id="div" style="width:100px; height:20px;  left:0px; top:0px; overflow:hidden; text-overflow:ellipsis;">
        <%--鼠标移上去则显示层,移开则隐藏--%>
      <nobr title='<%# Eval("productName") %>'>
         <a href= '<%#String.Format("javascript:OpenProductDetail({0})",Eval("productId")) %>'> <%# Eval("productName") %></a>
         </nobr>
      </div>

弹出模式窗体
function method(rowId)
{
    var row = document.getElementById(rowId);//获取行对象
    var url = "EditBrand.htm";
    //弹出模式窗体(隐藏状态栏,问号..)
    window.showModalDialog(url,row,
        "status:no;resizable:no;help:no;dialogWidth=600px;dialogHeight=450px");
}

弹出非模式窗体
function method(productId)
{
    var url = "EditProducts.aspx?productId="+productId;
    //弹出非模式窗体(隐藏状态栏,问号..)
    window.showModelessDialog(url,-1,
        "status:no;resizable:no;help:no;dialogWidth=600px;dialogHeight=450px");
}

///JavaScript进度条
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>加载状态条</title>
<style type="text/css">
<!--
body{
 font:12px "宋体";
}
#sysTitle{
 width:400px;
 margin:20% auto;
 padding:1px;
 border:1px solid #003366;
 background:#E7F3FF;
}
#sysTitle #sHeader{
 height:26px;
 padding-left:10px;
 line-height:26px;
 background:#6DA2BB;
 color:#F2F2F2;
}
#sysTitle #sBody{
 padding:30px 8px;
 position:relative;
}
#sBody #sbTotal{
 border:1px solid #000;
 height:16px;
}
#sbTotal #sbExec{
 width:0%;
 height:16px;
 background:#0099FF;
}
#sysTitle #sFooter{
 padding-left:8px;
 height:20px;
 line-height:20px;
 border-top:1px solid #003366;
}
-->
</style>
</head>

<body>
<a href="/">返回首页</a>
<div id="sysTitle">
 <div id="sHeader">正在执行,请稍候...</div>
    <div id="sBody">
     <div id="sbTotal">
         <div id="sbExec"></div>
        </div>
    </div>
    <div id="sFooter">正在执行...</div>
</div>
<script type="text/javascript">
<!--
loadStatus(1,100);
function $(curObj){
  return document.getElementById(curObj);
}
function loadStatus(preNum,totalNum){
 var curNum=preNum+1;
 var execPercent=parseInt(curNum/totalNum*100);
 $('sbExec').style.width=execPercent+"%";
 $('sFooter').innerHTML='正在执行'+execPercent+"%";
 if(curNum<totalNum){
  setTimeout('loadStatus('+curNum+','+totalNum+')',1);
 }else{
  $('sFooter').innerHTML='执行完成';
 }
}
-->
</script>
</body>
</html>

///将层放在flash上代码
<div>
<object codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0
            height=350 width=768 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>
  <PARAM NAME="movie" VALUE="Flash/top.swf">
  <PARAM NAME="quality" VALUE="high">
  <PARAM NAME="BGCOLOR" VALUE="#000000">
  <PARAM NAME="wmode" VALUE="transparent">
            <embed src="Flash/top.swf" quality="high"
            pluginspage="http://www.macromedia.com/go/getflashplayer"
            type="application/x-shockwave-flash" width="768"
            height="350"></embed>
          </object>
</div>