var 字串a = "hello";
字串a += " world";
"包含e:"+ (字串a.indexOf("e") >= 0) + " 长度:" + 字串a.length
"当前时间:" + new Date() + "\n" +
"格式yyyy/mm/dd:" + new Date('2022/11/30 10:35:32') + "\n" +
"格式mm/dd/yyyy:" + new Date('11/30/2022 10:35:32') + "\n" +
"格式yyyy-mm-dd:" + new Date('2022-11-30 10:35:32'.replace(/-/g,'/'));
var 数组a = [-1.2, 3.2, 15, 4.912];
数组a[2];
var 猫猫1 = {颜色:"白", 年龄:"15", 名字:"乖乖"};
猫猫1.名字
Math.E
Math.PI
Math.abs(-5.611)
Math.exp(2)
Math.sqrt(9)
Math.pow(27,1/3)
Math.pow(2,5)
Math.cos(0)
Math.sin(9)
Math.tan(5)
Math.atan(-7.3)
Math.acos(0.5)
Math.asin(0.3)
Math.log(6)
// ECMAScript 6支持,而ECMAScript 5.1不支持
Math.log10(6)
// ECMAScript 6支持,而ECMAScript 5.1不支持
Math.log2(6)
Math.ceil(4.13)
Math.floor(4.67)
Math.round(4.83)
Math.trunc(4.83)
Math.random()
Math.max(1,2,-3)
Math.min(1,2,-3)
'Hello' === 'hello' || 'a' < 'A' || 'a' != 'A'
"Hello World! World is yourself.".replace("World", "Feeling");
"Hello World! World is yourself.".replace(/World/g, "Feeling");
'Hello'.startsWith('h')
'Hello'.endsWith('o')
'Hello'.substring(2, 5)
'hello'.charAt(2)
'hello'.concat(' world')
'1,2,3,4'.split(',')
'hello'.indexOf('e')
'hello'.lastIndexOf('l')
'hello'.length
var 字符串a = "abc1233hello";
var 规则表达式a = /3{2,}/ig;
字符串a.search(规则表达式a)
'Hello'.toLowerCase()
'Hello'.toUpperCase()
var 数组a = [-1.2, 3.2, 15, 4.912];
数组a.length
var 数组a = [-1.2, 3.2, 15, 4.912];
数组a.push(-47);
var 数组a = [-1.2, 3.2, 15, 4.912];
数组a.pop()
var 字符串a = "abc1233hello";
var 规则表达式a = /3{2,}/ig;
字符串a.search(规则表达式a) >= 0
var 字符串a = "abc1233hello";
var 规则表达式a = /\S*3{2,}\S*/ig;
字符串a.search(规则表达式a) >= 0
var 数组a = ['A', 'B', 'C', 'D'];
数组a.includes('C');
var 值1='你好'
isNaN(值1 - 1)
var 数组a = ['A', 'B', 'C', 'D'];
var 字符串a = "abc1233hello";
数组a.includes('C') && (数组a.length >= 8 || 字符串a.length < 5 || !字符串a.endsWith("h"));
"当前时间:" + "\n" +
"new Date() = " + new Date()+ "\n" +
"new Date().getTime() = " + new Date().getTime() + "\n" +
"new Date().toLocaleString() = " + new Date().toLocaleString()+ "\n" +
"new Date().toGMTString() = " + new Date().toGMTString()+ "\n" +
"new Date().toISOString() = " + new Date().toISOString()+ "\n" +
"new Date().toUTCString() = " + new Date().toUTCString()+ "\n" +
"new Date().toString() = " + new Date().toString()+ "\n" +
"new Date().toJSON() = " + new Date().toJSON()+ "\n" +
"new Date().toDateString() = " + new Date().toDateString()+ "\n" +
"new Date().toTimeString() = " + new Date().toTimeString()+ "\n" +
"new Date().toLocaleDateString() = " + new Date().toLocaleDateString()+ "\n" +
"new Date().toLocaleTimeString() = " + new Date().toLocaleTimeString()
new Date('2022/11/30 10:35:32').toLocaleString() + "\n" +
new Date('11/30/2022 10:35:32').toLocaleString() + "\n" +
new Date('2022-11-30 10:35:32'.replace(/-/g,'/')).toLocaleString() + "\n" +
new Date('2022/11/30') + "\n" +
new Date('2022-11-30'.replace(/-/g,'/'))
function formatDate(date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h =date.getHours();
h = h < 10 ? ('0' + h) : h;
var M =date.getMinutes();
M = M < 10 ? ('0' + M) : M;
var s =date.getSeconds();
s = s < 10 ? ('0' + s) : s;
return y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s;
}
formatDate(new Date());
var 时间b = new Date('11/30/2022 10:35:32');
"年:" + 时间b.getFullYear() + "\n月:" + (时间b.getMonth() + 1) + "\n日:" + 时间b.getDate()
+ "\n星期:" + 时间b.getDay() + "\n小时:" + 时间b.getHours()+ "\n分钟:" + 时间b.getMinutes()
+ "\n秒:" + 时间b.getSeconds();
new Date().getDay() == 0
new Date('2012/05/19').getTime() > new Date('2016/05/19 09:23:12').getTime()
function addStyle(style) {
var node = document.createElement("style");
node.id = "mystyleid";
node.type = "text/css";
node.innerHTML = style.replace(/\n/g," ");
document.getElementsByTagName("HEAD").item(0).appendChild(node);
};
addStyle("body { background-color:black; color:#CCFF99; }");
function removeNode(id) {
var node = document.getElementById(id);
if ( node != null )
node.parentNode.removeChild(node);
};
removeNode("mystyleid");
document.cookie;
document.documentElement.scrollHeight || document.body.scrollHeight;
document.documentElement.scrollWidth || document.body.scrollWidth;
window.getSelection().removeAllRanges();
var selection = window.getSelection();
var range = document.createRange();
range.selectNode(document.documentElement);
selection.addRange(range);
window.getSelection().removeAllRanges();
function selectNode(id) {
window.getSelection().removeAllRanges();
var selection = window.getSelection();
var range = document.createRange();
range.selectNode(document.getElementById(id));
selection.addRange(range);
};
selectNode("someid");
window.getSelection().toString();
var selectionObj = window.getSelection();
var rangeObj = selectionObj.getRangeAt(0);
var docFragment = rangeObj.cloneContents();
var div = document.createElement("div");
div.appendChild(docFragment);
div.innerHTML;
window.scrollTo(50,70 );
document.body.contentEditable=true;
alert("人生得意须尽欢!");
confirm("能饮一杯无?");
prompt("君不见");
window.open("http://www.nlc.cn");