JavaScript DOM操作案例点击按钮修改div的属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="button" value="修改属性" id="bt"/> <div id="dv"></div> <!--引入js文件--> <script src="common.js"></script> <script> //凡是css中这个属性是多个单词的写法,js代码中DOM操作的时候,把-干掉,后面的单词大写 //点击按钮,修改div的宽高和背景颜色 my$("bt").onclick = function () { my$("dv").style.width = "300px"; my$("dv").style.height = "300px"; my$("dv").style.backgroundColor = "deeppink"; }; </script> </body> </html>