javaScript:
js三种导入方式:
行内式:
<input type='button' name='' onclick="alert('ok!');">
内嵌式:
<script type="text/javascript">
alert('ok');
</script>
外链式:
<script src='js/scripts.js'></script>
js常见的数据类型“
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var iNum=10
document.write(iNum)
document.write('<br>')
document.write(typeof(iNum))
document.write('<hr>')
var sStr='1234';
document.write(sStr)
document.write('<br>')
document.write(typeof(sStr))
document.write('<hr>')
var bIsTrue=false;
document.write(bIsTrue)
document.write('<br>')
document.write(typeof(bIsTrue))
document.write('<hr>')
var unData;
document.write(unData)
document.write('<br>')
document.write(typeof(unData))
document.write('<hr>')
var nullData=null;
document.write(nullData)
document.write('<br>')
document.write(typeof(nullData))
document.write('<hr>')
var oObj={
name:'隔壁老王',
age:88
}
document.write(oObj)
document.write('<br>')
document.write(typeof(oObj))
document.write('<hr>')
</script>
</body>
</html>
js变量命名规则:
? 1、区分大小写 ? 2、第一个字符必须是字母、下划线(_)或者美元符号($) ? 3、其他字符可以是字母、下划线、美元符或数字
js函数的定义和调用:
定义一个函数:
<script>
function fnAlert(){
alert('hello');
}
fnAlert();
</script>
定义一个带参数的函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function fnSum(iNum1,iNum2){
return iNum1+iNum2
alert('hello');
}
var sum=fnSum(1,2);
document.write(sum);
</script>
</body>
</html>
定义一个全局变量:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var a=12;
function myalert(){
a++;
}
myalert();
console.log(a);
</script>
</body>
</html>
|