每一句js代码是语句,注意加分号
1.“;”分号要在英文状态下输入,同样,JS中的代码和符号都要在英文状态下输入。
2. 虽然分号“;”也可以不写,但我们要养成编程的好习惯,记得在语句末尾写上分号。
1.“;”分号要在英文状态下输入,同样,JS中的代码和符号都要在英文状态下输入。
2. 虽然分号“;”也可以不写,但我们要养成编程的好习惯,记得在语句末尾写上分号。
2015-08-04
按顺序加载页面
javascript作为一种脚本语言可以放在html页面中任何位置,但是浏览器解释html时是按先后顺序的,所以前面的script就先被执行。比如进行页面显示初始化的js必须放在head里面,因为初始化都要求提前进行(如给页面body设置css等);而如果是通过事件调用执行的function那么对位置没什么要求的。
javascript作为一种脚本语言可以放在html页面中任何位置,但是浏览器解释html时是按先后顺序的,所以前面的script就先被执行。比如进行页面显示初始化的js必须放在head里面,因为初始化都要求提前进行(如给页面body设置css等);而如果是通过事件调用执行的function那么对位置没什么要求的。
2015-08-04
<script src="script.js"></script>代码引用外部script.js文件,后缀是.js
2015-08-04
成对出现
<script type="text/javascript">表示在<script></script>之间的是文本类型(text),javascript是为了告诉浏览器里面的文本是属于JavaScript语言。
<script type="text/javascript">表示在<script></script>之间的是文本类型(text),javascript是为了告诉浏览器里面的文本是属于JavaScript语言。
2015-08-04
Attention:大小写,分号
<script type="text/javascript">
document.write("hello");
document.getElementById("p1").style.color="blue";
document.getElementById("p2").style.background="red";
document.getElementById("p3").style.border="2px dashed red";
</script>
<script type="text/javascript">
document.write("hello");
document.getElementById("p1").style.color="blue";
document.getElementById("p2").style.background="red";
document.getElementById("p3").style.border="2px dashed red";
</script>
2015-08-04
写完函数事件后,不要忘了回到input表单,设置鼠标点击事件onclick="函数名"
<input type="button" value="改变颜色" onclick="tp()">
<input type="button" value="改变宽高" onclick="whchange()" >
<input type="button" value="隐藏内容" onclick="hidetext()">
<input type="button" value="显示内容" onclick="showtext()" >
<input type="button" value="改变颜色" onclick="tp()">
<input type="button" value="改变宽高" onclick="whchange()" >
<input type="button" value="隐藏内容" onclick="hidetext()">
<input type="button" value="显示内容" onclick="showtext()" >
//定义"隐藏内容"的函数
function hidetext()
{
var mychar= document.getElementById("txt");
mychar.style.display="none";
}
//定义"显示内容"的函数
function showtext()
{
var mychar = document.getElementById("txt");
mychar.style.display="block";
}
function hidetext()
{
var mychar= document.getElementById("txt");
mychar.style.display="none";
}
//定义"显示内容"的函数
function showtext()
{
var mychar = document.getElementById("txt");
mychar.style.display="block";
}