function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
// 数组里找到并删除
positionsObj.splice(positionsObj.findIndex(v => {
return v.id === target
}), 1);
// 指定位置插入
positionsObj.splice(parseInt(previewPoint.attr("data-prev-id")) + 1, 0, {
x: left,
y: top,
id: lastId
});
Object.prototype.toString.call(obj) === '[object Object]'
//表达式 返回值
typeof undefined 'undefined'
typeof null 'object'
typeof true 'boolean'
typeof 123 'number'
typeof "abc" 'string'
typeof function() {} 'function'
typeof {} 'object'
typeof [] 'object'
var a=''; console.log(!!a)
VM15885:1 false
undefined
var a=null; console.log(!!a)
VM15913:1 false
undefined
var a=undefined; console.log(!!a)
VM15937:1 false
undefined
var a=''; console.log(!a)
VM15952:1 true
undefined
var a=null; console.log(!a)
VM15967:1 true
undefined
var a=undefined; console.log(!a)
VM15989:1 true
<!DOCTYPE html>
<html>
<body>
<button onclick="alert('clicked')">click<button>
<p id="p">
JavaScript 能够直接写入 HTML 输出流中:
</p>
<script>
document.write("<p>hello</p>");
x=document.getElementById("p");
x.innerHTML="test:change the element text";
x.outHTML="";
if(x.innerHTML.match('test'))
x.innerHTML+='test';
</script>
<p>
您只能在 HTML 输出流中使用 <strong>document.write<
>。
如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。
</p>
</body>
<html>
var carname=new String;//声明固定类型变量.
var x= new Number;
var y= new Boolean;
var cars= new Array;
var person= new Object;
var str = new String;
var arr2=[];
var arr=new Array('dasf',123,new Array);//Array 大写
var index=lates.findIndex(function(elem){return elem==id;});
if(-1==index){
lates.push(id);
$(ele).removeClass("btn-default");
$(ele).addClass("btn-warning");
}else{
lates.splice(index,1);//删除从第index开始的一个元素,还有第三个参数,如果填写就用第三个参数替换被删除的元素
$(ele).removeClass("btn-warning");
$(ele).addClass("btn-default");
}</pre>
document.write(arr[0]);
arr.slice()//和splice差不多,唯一区别就是不改变传入数组而是返回新数组
for(eachName in arr)
{
document.write(eachName+":"+arr[eachName]);//遍历输出所有名和值.
}
console.log(obj.one);
console.log(obj['two']);
var arr= [
{code: '', selected: false},
{code: '', selected: false},
{code: '', selected: false},
];
console.log(arr);
arr=arr.map((val)=>{val.code="1";return val;});
console.log(arr)
$.ajax({
//这里传入的是一个Object,回调函数也一起传进去了.
url: form.attr("action"),
type: form.attr("method"),
data: form.serialize(),
success: function (data)
{
//前面要加上'http://'才是绝对地址,要不然系统会当成相对地址处理
temp=document.domain+data['address'];
setTimeout("window.location.href='http://"+temp+"'",3000);
}
});
function funName()
{
arguments.length;//传入参数的个数
argument[0];//获取第一个参数.
}
temp=JSON.stringify({lates:lates,absents:absents});//对象转JSON
console.log(JSON.parse(temp));//JSON转对象
var showFun = function (count) {
for(var i=0;i<count;i++){
document.write("
Hello World");
}
};
评论区