比较运算符
== 等于
=== 全等(值和类型相等)
条件运算符
variablename=(condition)?value1:value2
如果condition为true;则variable为value1,否则为value2;
1.js事件
事件是可以被js侦测到的行为
onchange 用户改变域的内容
onclick 鼠标点击某个对象
onfocus/onblur 元素获得/失去焦点
onmouseover/onmouseout 鼠标被移到/移开某元素
onload/onunload 用户进入/离开页面
例题
【html】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="text1.css" rel="stylesheet" type="text/css" />
<script src="text.js"></script>
</head>
<body>
<div id="div1" οnmοuseοver="change()" οnmοuseοut="change1()">huanghuang</div>
</body>
</html>
【text1.css】
#div1
{
width:100px;
height:100px;
background-color:#006;
}
【text,js】
// JavaScript Document
function change(){
document.getElementById("div1").style.backgroundColor="red";}
function change1(){
document.getElementById("div1").style.backgroundColor="#006";}
2函数语法
函数就是包裹在花括号中的代码块,前面使用了管家词function。
function name()
{
这里是要执行的代码
}
比较运算符
== 等于
=== 全等(值和类型相等)
条件运算符
variablename=(condition)?value1:value2
如果condition为true;则variable为value1,否则为value2;
1.js事件
事件是可以被js侦测到的行为
onchange 用户改变域的内容
onclick 鼠标点击某个对象
onfocus/onblur 元素获得/失去焦点
onmouseover/onmouseout 鼠标被移到/移开某元素
onload/onunload 用户进入/离开页面
例题
【html】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="text1.css" rel="stylesheet" type="text/css" />
<script src="text.js"></script>
</head>
<body>
<div id="div1" οnmοuseοver="change()" οnmοuseοut="change1()">huanghuang</div>
</body>
</html>
【text1.css】
#div1
{
width:100px;
height:100px;
background-color:#006;
}
【text,js】
// JavaScript Document
function change(){
document.getElementById("div1").style.backgroundColor="red";}
function change1(){
document.getElementById("div1").style.backgroundColor="#006";}
2函数语法
函数就是包裹在花括号中的代码块,前面使用了管家词function。
function name()
{
这里是要执行的代码
}