javascript作为一种脚本语言可以放在html页面中任何位置,但是浏览器解释html时是按先后顺序的,所以前面的script就先被执行。比如进行页面显示初始化的js必须放在head里面,因为初始化都要求提前进行(如给页面body设置css等);而如果是通过事件调用执行的function那么对位置没什么要求的。
2016-03-26
function a1()
{
var mychar=document.getElementById("txt");
mychar.style.color="red";
mychar.style.backgroundColor="#ccc";
}
//定义"改变宽高"的函数
function a2()
{
var mychar=document.getElementById("txt");
mychar.style.height="400px";
mychar.style.width="400px";
}
{
var mychar=document.getElementById("txt");
mychar.style.color="red";
mychar.style.backgroundColor="#ccc";
}
//定义"改变宽高"的函数
function a2()
{
var mychar=document.getElementById("txt");
mychar.style.height="400px";
mychar.style.width="400px";
}
<p id="p1">我是第一段文字</p>
<p id="p2">我是第二段文字</p>
<script type="text/javascript">
docunment.write("hello")
docunment.getElementById("p1").style.color="blue";
</script>
<p id="p2">我是第二段文字</p>
<script type="text/javascript">
docunment.write("hello")
docunment.getElementById("p1").style.color="blue";
</script>
2016-03-26
var mychar=doucument.getElementById("con") ;
document.write("结果:"+mychar); //输出获取的P标签。 怎么不对呢,错在哪里了。。
document.write("结果:"+mychar); //输出获取的P标签。 怎么不对呢,错在哪里了。。
2016-03-26