通过两种方法实现在HTML页面加载完毕后运行某个js
js
<script>
window.onload = function(){
var apple = "Apple";
alert(apple);
}
</script>
jquery
<script>
$(document).ready(function(){
var apple = "Apple";
alert(apple);
})
</script>
关于input的那些事
- input框的值
var value = $("input").val("")//清空input框获得的值
var value = $("input").val()//获取value的值
JS中遍历数组和对象
- 数组
返回的数组为data;
/*创建数组*/
var person = new Array["Jay","Hannah","Hathaway","Romeo"];
for(i=0;i<person.length;i++){
document.write(person[i]+"<br/>");
}
- 对象
/*创建数组*/
var person = new object();
person.name = "Jay";
person.wife = "Hannah";
person.daughter = "Hathaway";
person.son = "Romeo";
for(var i in person){
document.write(person[i]+"<br/>");
}
以这个例子来看,输出结果是相同的。注意:数组表示有序数据的集合,而对象表示无序数据的集合;