js屬性有哪些 js寫入HTML js對事件可以做出反應 js改變HTML的內容 js能改變HTML的圖像
document.write() 顯示
onclick是指單擊事件
alert()是指彈出框 <button type="button" onclick="alert('WELCOME')">點擊這里</button>
getElementById("demo") //查找id是demo的元素
innerHTML雙向功能 1.獲取對象的內容,2.向對象中插入內容
<html> <body> <p id="demo"> JavaScript 能改變HTML的內容 </p>
<script> function Myfunction(){ x=document.getElementById("demo");//找到元素 x.innerHTML="HELLO WORLD";//改變內容 } <\script> <button type="button" onclick="Myfunction()">點擊這里<\button> <\body> <html>
點擊圖像使燈亮和燈滅 <html> <body> <script> function changImage(){ element=document.getElementById('myimage'); if(element.src.match("bulbon")){ element.src="/i/eg_bulboff.git"; } else{ element.src="/i/eg_bulbon.gif"; } <\script> <img id="myimage" onclick="changImage()" src="/i/eg_bulboff.gif">
<\body>
<\html>
浙公網安備 33010602011771號