令我头疼的JavaScript

1、JavaScript 取后台变量
       var printinfo="<% = AirportPrintInfo %>"  ,前提是这个变量在后台声明为public的,(我写的时候没写引号,糊涂 啊)
2、用脚本给label赋值
     label 在客户端是span ,没有value,却有innerHTML , alert(address.innerHTML); 这样就可以了
3、多维数组
     在后台定义的数组的数组,js不认这种格式 ,所以response.Write("") ,这种格式就可以认了: var obj = [[1,"address1","link1"],[2,"address2","link2"],[3,"address3","link3"]]   obj[0][1] 可以取到任意你想要的值

4、在C#里面弹出脚本提示的方法有:
  this.RegisterClientScriptBlock("a", "<script language=javascript>window.alert('取消核实工作失败!');</script>");
this.RegisterClientScriptBlock("abc", "<script language=javascript>window.location.href='jperror.aspx?errorinfo=定座失败,请拨打我们的客服热线:400-818-9588';</script>");
 

 5、在javascript 中 两个整数相加 

    var i=12;

    var j=3;

alert(parseInt(i)+parseInt(j));   就可以得到15 直接相加等于123,默认为字符串相连,但我用不太好使,最简单的方法 j+1 就自动会转换成整数相加,

大不了i+1+j+1-2呗  ,省事

 

 

6、页面弹出div  页面变灰不可以再点击

首先,原理是三个div 

<div> 这个包括了整个页面的东西</div>

<div>这是个弹出的div</div> ---这个是弹出层

<div> 空的且独立的div</div>---这个是遮盖层

这三个div是相互独立 ,不相互嵌套的,点击按钮弹出的时候,弹出后两个div  对遮盖层进行css设置就OK了

  <script type="text/javascript" >
      //页面内弹出提示信息
        function ShowTip(div1,div2){
            div1 == getObject(div1);
            div2 == getObject(div2);
            Member_Main == getObject(Member_Main);
            div1.style.display="block";
            div1.style.width=document.body.scrollWidth;
            div1.style.height=document.body.scrollHeight;
            div2.style.display="block";
            div2.style.left = (document.body.clientWidth / 2) - (div2.offsetWidth / 2);
            div2.style.top = (document.body.clientHeight / 2 + document.body.scrollTop) - (div2.offsetHeight / 2);
            Member_Main.className = "Member_hide"
        }
       
        function CloseTip(div1,div2){
         div1 == getObject(div1);
            div2 == getObject(div2);
         div1.style.display="none";
            div2.style.display="none";
         Member_Main.className = "";
        }
       
        function getObject(objectId) {
             if(document.getElementById && document.getElementById(objectId)) {
         // W3C DOM
            return document.getElementById(objectId);
             }
             else if (document.all && document.all(objectId)) {
         // MSIE 4 DOM
            return document.all(objectId);
             }
             else if (document.layers && document.layers[objectId]) {
         // NN 4 DOM.. note: this won't find nested layers
            return document.layers[objectId];
             }
             else {
            return false;
            }
        }
  </script>

/*遮盖层*/
.layover {
 position:absolute;
 top:0px;
 FILTER: alpha(opacity=20);
 -moz-opacity:.2;
 opacity:0.2;
 background-color:#999999;
 z-index:101;
 left: 0px;
 display:none;
}

弹出层的样式可以自己定义

7、为了防止别人盗用自己的Iframe ,可以在顶部加句脚本

if (top.location != location)
    {top.location.href = http://www.9588.com/;}

 

8. 取dropdownlist的选中值和文本?设置dropdownlist 的选中值?
var ddlYear = document.getElementById("ddlYear");
 var year = ddlYear.options[ddlYear.selectedIndex].value; value是值,text是文本
for (var i = 0; i < ddlYear.options.length; i++) {
            if (parseInt(ddlYear.options[i].value) == currentYear) {
                ddlYear.options[i].selected = true;
            }
        }--为dropdownlist重新赋值选择项
9.截取字符串
var inputDate = document.getElementById("inputDate");2010-10
 var month = inputDate.value.substr(5, 2);
 
10 元素的隐藏显示?
  if (spanYear.style.display == "none") {
            ddlYear.style.display = "none";
            $("#spanYear").show();
        }
11
function ckeckform()
   {
       var regex = /^\d{4}\-\d{1,2}\-\d{1,2}/;
       var txtStart = document.getElementById("txtStartTime");
       var txtEnd = document.getElementById("txtEndTime")
      
       if (txtStart.value != "" && !regex.test(txtStart.value))
       {
           alert("开始时间格式不正确");
           txtStart.focus();
           return false;
       }
      
       if (txtEnd.value != "" && !regex.test(txtEnd.value))
       {
           alert("结束时间格式不正确");
           txtEnd.focus();
           return false;
       }
       return true;
   } 
12\对于原生态的javascript,了解不是很深,总是由于很弱智的错误耽误很多时间

比如:给div里面赋值的属性是innerHTML,我写成innerHtml

 在事件里面给某个元素赋值:<input type="button" onclick="txtName.value='china'"><input type="text" id="txtName">

 

<INPUT TYPE="button" onclick="a1.innerHTML='<font color=red>*</font>'">
<div id=a1></div>
 

 

posted @ 2009-09-27 16:20  张倩  阅读(472)  评论(0编辑  收藏  举报