A stray ant can only move by itself

前端js常见问题

textarea

textarea的text属性与value属性注意区分,发送到服务器的是value值

select标签

select标签通过js生成的option设置默认选中状态必须在生成的过程中进行设置,
在生成后设置:$(“select””).val() 和$(“select””).find(“option[value=”+yes+”]””).attr(“selected””,”selected””)都不会生效;
input 标签不填任何内容值为 “”

前端js 代码中遍历 key:value结构数据

1
2
3
for(var key in obj){	//	key为map集合中的每个元素的key
var value = obj[key] // value 为对应key 对应的value
}

遍历json 对象 与遍历map相同

1
2
3
for(var item in person){
alert("person中"+item+"的值="+person[item]);
}

数组删除指定元素的方法

方法一:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//定义删除方法
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
// 定义查询下标的方法
Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};

方法二:
array 表示数组,item表示数组中的元素,
$.inArray 获取item在array 中的下标,splice(index, num)表示从index位置开始删除num个元素

1
array.splice($.inArray(item, array), 1);

复制一个对象中的数据到新的对象中

1
$.extend(newData, oldData);
支付宝打赏 微信打赏

赞赏是不耍流氓的鼓励