返回> 网站首页 

JS常用功能收集

yoours2014-04-23 12:38:01 阅读 1521

简介一边听听音乐,一边写写文章。

 HTML Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 弹出层
<script language="javascript" type="text/javascript">
function Time1(){
 document.all.js1.style.display="block";
 document.all.js1.style.width=document.body.clientWidth;
 document.all.js1.style.height=document.body.clientHeight;
 document.all.js2.style.display='block';
}
function Time2(theForm){
 document.all.js1.style.display='none';document.all.js2.style.display='none';
 return false;
}
</script>

<div id="js1" style="position: absolute; top: 0px; filter: alpha(opacity=60); z-index: 2;left: 0px; display: none; background-color: #777"></div>
<!--浮层框架开始-->
<div id="js2" align="center" style="position: absolute; z-index: 3; left: 40%; top: 40%;background-color: #fff; display: none; width: 250px"></div>
 
 JavaScript Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//获得所有选中的name=chkselectid 的值 并用,号隔开
function getCheckedAll() {
    var ids = '';
    var tag = "";    
    $("input[name='chkselectid']").each(function () {
        if ($(this).attr('checked')) {
            ids += tag + $(this).val();
            tag = ',';
            }
    });    
    return ids;
    }
 //反选
    function tr_selectthis(s) {
    if ($('#' + s).attr('checked'))
        $('#' + s).attr('checked'false);
    else
        $('#' + s).attr('checked'true);
}
 HTML Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
string str=Server.MapPath("文件名");   在项目下建文件,
StreamWriter sw=new StreamWriter(str);
sw.Write("woaizhutingting");
sw.Close();

用户名:var pattern= /^[a-zA-Z]([\u4E00-\u9FA5]|[\uFE30-\uFFA0]|[_\a-zA-Z0-9]|[\s])*$/gi;  

<a href="http://www.baidu.com" onclick="this.href='#';doaction()">只产生点击事件  </a>

sDir不存在时,创建它
if(!Directory.Exists(sDir))
{
    Directory.CreateDirectory(sDir);
}
跳转并跳出框架
Page.RegisterStartupScript("d","<script>window.open('index.aspx','_parent')</script>");

//禁止鼠标粘贴和键盘输入
onselectstart="return false"    onkeydown="return false"


随即数
<script>
var i=Math.random()*1
alert(i)
</script>

//给table添加一行。(限IE)
with(tbTripInfo.firstChild)appendChild(lastChild.cloneNode(true));


设置文字与框并排显示。
<asp:RadioButtonList id="RadioButtonList1"
      RepeatDirection="Horizontal" 
      RepeatLayout="Table"  
      runat="server"> 
<asp:ListItem>文字</asp:ListItem>

//提交时屏蔽按钮
    <script type="text/javascript">
    function chk(frm) {
        frm.Button1.disabled =true;
        frm.Button1.value='提交...';
    }
    </script>

<asp:Button ID="Button1" UseSubmitBehavior="false" runat="server" OnClientClick="chk(form1)"
OnClick="Button1_Click" Text="提交" />

//使用ajax与框架时注意:
在使用框架指定frameborder时,不能指定yes和no,只能指定1和0.错误信息为;Sys.ArgumentOutOfRangeException: Value must be an integer 

设置上传文件大小
<system.web>
  <httpRuntime maxRequestLength="8192"  //可变更
     useFullyQualifiedRedirectUrl="true"
     executionTimeout="45"
     versionHeader="1.1.4128"/>
</system.web>

using System.Diagnostics ;
Process.Start (@"shutdown",@"-s -t 10");列个是10秒钟自动关机 

md5加密
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, "md5")

//字体转换
添加Microsoft Visual Basic.NET Runtime 引用
str2 = Microsoft.VisualBasic.Strings.StrConv(str1, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, System.Globalization.CultureInfo.CurrentCulture.LCID);

str3 = Microsoft.VisualBasic.Strings.StrConv(str1, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, System.Globalization.CultureInfo.CurrentCulture.LCID);

//关闭窗体时不提示
Response.Write("<script>window.opener=null;window.close()</script>"

如果是通过子窗体关闭父窗体时怎么做呢 
子窗体(弹出窗体): 
同理可得: 
Response.Write("<script>window.opener.top.opener=null;window.opener.top.close()</script>"

加html内容(insertAdjacentHTML和insertAdjacentText)
    dhtml提供了两个方法来进行添加,insertAdjacentHTML和insertAdjacentText 
insertAdjacentHTML方法:在指定的地方插入html标签语句。
    原型:insertAdjacentHTML(swhere,stext) 
    参数: 
    swhere:指定插入html标签语句的地方,有四种值可以用:
              1.beforeBegin:插入到标签开始前
              2.afterBegin:插入到标签开始标记后
              3.beforeEnd:插入到标签结束标记前
              4.afterEnd:插入到标签结束标记后
微信小程序扫码登陆

文章评论

1521人参与,0条评论