js小技巧收集

6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("i
nput").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function

8.JS中的字符型转换成数值型:parseInt(),parseFloat()

36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();
37.返回字符串2在字符串1中出现的位置:String1.indexOf("String2")!=-1则说明没找到.
38.取字符串中指定位置的一个字符:StringA.charAt(9);
39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);

41.定义日期型变量:var today = new Date();
42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到
四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dat
eObj.getHours()得到小时,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTi
me(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置月,dateObj.setDate(va
l)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]

66.防止用户对文本框中输入文本:onfocus="this.blur()"

88.window.location的属性: protocol(http:),hostname(example.com),port(80),host(e
xample.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),href(全部的信
息)  

禁止右键
document.oncontextmenu = function() { return false;}
禁止保存
<noscript><iframe src="*.htm"></iframe></noscript>
禁 止选取<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>
禁止粘贴
<input type=text onpaste="return false">
地址栏图标
<link rel="Shortcut Icon" href="favicon.ico">
favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
收藏栏图标
<link rel="Bookmark" href="favicon.ico">
查看源码
<input type=button value=查看网页源代码 onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
关闭输入法
<input style="ime-mode:disabled">
自动全选
<input type=text name=text1 value="123" onfocus="this.select()">
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
文本框的默认值
<input type=text value="123" onfocus="alert(this.defaultValue)">

原文地址:https://www.cnblogs.com/nianshi/p/1604641.html