js改变HTML元素样式
html
<p id="demo">js改变HTML元素样式p> <button type="button" onclick="MyTest(this)">测试button>
js
function MyTest() { // 改变元素的样式,将字号改为40,颜色改为红色
var test = document.getElementById('demo'); test.style.fontSize='40px'; test.style.color='red'; }
<p id="demo">js改变HTML元素样式p> <button type="button" onclick="MyTest(this)">测试button>
function MyTest() { // 改变元素的样式,将字号改为40,颜色改为红色
var test = document.getElementById('demo'); test.style.fontSize='40px'; test.style.color='red'; }