javascript [1 day]

1、<div id="div1" onmouseover="document.getElementById('div1').style.background='red';document.getElementById('div1').style.width='200px';document.getElementById('div1').style.height='200px';">         //行间

 

2、<div id="div1" onmouseover=red();>

<script>

  function red(){

          document.getElementById('div1').style.background='red'; 

          document.getElementById('div1').style.width='200px';

          document.getElementById('div1').style.height='200px';

  }

</script>

 

3、<script>

  function red(){

          var a=document.getElementById('div1');

          a.style.background='red'; 

          a.style.width='200px';

          a.style.height='200px';

  }

</script>

 

4、<script>                        //定义和调用缺一不可

function show(){

        alert('abc');        //函数定义

}

show();            //函数调用

</script>

 

 

js兼容问题:在ff下直接使用ID存在问题,document.getElementById()在任何浏览器下都可以使用

任何标签都可以加id,包括link:

<head>

<link id="li" rel="stylesheet" href="css1.css" type="text/css">

<script>

function a(){

  var ol=document.getElementById('li');

  ol.href='css1.css';

}

function b(){  

  var ol=document.getElementById('li');

  ol.href='css2.css';

}

</script>

</head>

<body>

  <input type="button" value="皮肤1" onclick="a()">

  <input type="button" value="皮肤2" onclick="b()">

</body>

 任何标签的任何属性,都可以修改(像link标签的href属性)

JS修改html的样式,再加.style,如a.style.background="#f00";  也可以写成a.style['background']="#f00";凡是可以写点的地方都可以用[]代替

html里怎么写,js就怎么写[className是唯一的例外,class在js是关键字/保留字]:

<head>
<script>
  function a(){
      var a=document.getElementById('b');
      a.value='a';    
  }
</script>
</head>
<body>
<input id="b" type="text">
<input type="button" onclick="a()">
<body>

posted @ 2013-04-28 16:05  菜蛋  阅读(130)  评论(0编辑  收藏  举报