-------------------------------for循环----------------------------------------------
function text(){
var person={fname:"daren",lname:"xiaoren",num:15};<!--数组-->
var txt;
for(x in person){
txt = txt + person[x];
alert(txt);
}
}
-------------------------------------while循环--------------------------------------
function textb() {
var y = document.getElementsByTagName("input");<!--获取对应的input标签-->
alert(y.length);
for(var i;i<y.length;i++){
alert(y[x].type + y[x].value);
}
}
</script>
</head>
<body>
<input type="button" value="for" οnclick="text()"/>
<input type="button" value="while" οnclick="texta()"/><br>
<input type="button" value="ddd" οnclick="textb()"/>
<div>
<input type="button" value="aaa"/>
</div>
</body>
-------------------------onload与onunload事件-------------------------------
<script type="text/javascript">
function text(){
alert("欢迎使用!");
}
function texta(){
alert("欢迎再次使用!");
}
</script>
</head>
<body οnlοad="text()" οnunlοad="texta()"><!---onload表示进入提示,onunload表示退出提示-->
</body>
----------------------onmousedown与onmouseup事件------简单的onfocus与onblur事件------------------
<script>
function mouseDown()
{
document.getElementById("p1").style.color="red";
}
function mouseUp()
{
document.getElementById("p1").style.color="green";
}
function setStyle(x)
{
var b = document.getElementById("fname");
b.value="sssssssssssssssss";
}
function sss(x)
{
var b = document.getElementById("fname");
b.value="ssdddddddssss";
}
</script>
</head>
<body>
<p id="p1" οnmοusedοwn="mouseDown()" οnmοuseup="mouseUp()">
请点击文本!mouseDown() 函数当鼠标按钮在段落上被按下时触发。此函数把文本颜色设置为红色。mouseUp() 函数在鼠标按钮被释放时触发。mouseUp() 函数把文本的颜色设置为绿色。
</p>
<input type="text" οnfοcus="setStyle(this)" οnblur="sss(this)" id="fname" /><!--表示获得焦点与逝去焦点-->
</body>
-----------------location.href链接事件----------------history的事件-----------------------------------------------
<script type="text/javascript">
function text(){
var username = document.getElementById("username").value;<!--location.href链接事件-->
location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=39042058_10_oem_dg&wd=" + username + "&oq=%25E7%25BE%258E%25E5%25A5%25B3&rsv_pq=a56917aa00036e5e&rsv_t=f3d52VErBXhLLQojwGOl6QWPmq%2BKHnhYMLUZoXfI754KyvH4qaG1e7Ul7ig8ckiIoNiy5r1AwsqR&rqlang=cn&rsv_enter=0&rsv_sug=1";
}
function texta(){
window.history.back();<!--浏览器返回先前页面-->
}
function textb(){
window.history.forward();<!--浏览器显示下一个页面-->
}
function textc(){
window.history.go();<!--刷新-->
}
</script>
</head>
<body>
<font action="">
用户名:<input type="text" id="username"/>
<input type="button" value="ggggg" οnclick="text()"/>
</font>
<input type="button" value="ahjahf" οnclick="texta()"/>
<input type="button" value="ahjahf" οnclick="textb()"/>
<input type="button" value="ahjahf" οnclick="textc()"/>
</body>