1、<div >         //行间

 

2、<div 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 >

<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 >
<body>

相关文章:

  • 2021-08-06
  • 2021-12-21
  • 2022-02-22
  • 2021-06-23
  • 2021-08-04
  • 2021-10-04
  • 2021-06-14
  • 2021-07-16
猜你喜欢
  • 2021-04-05
  • 2022-12-23
  • 2021-08-25
  • 2021-12-03
  • 2021-07-20
  • 2021-04-04
相关资源
相似解决方案