為什么一個按鈕都不能運行???
?<form>
? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->
? ? <input type="button" value="改變顏色"? onClick="color()">??
? ? <input type="button" value="改變寬高" onClick="WH()">
? ? <input type="button" value="隱藏內容" onClick="hide()">
? ? <input type="button" value="顯示內容" onClick="dis()">
? ? <input type="button" value="取消設置" onClick="repeal()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數
? ? function color(){
? ? ? ? var pre=document.getElementById("con");
? ? ? ? pre.style.color="red";
? ? }
//定義"改變寬高"的函數
? ? function WH(){
? ? ? ? var txt=document.getElementById("txt");?
? ? ? ? txt.style.height="800";
? ? ? ? txt.style.width="300";
? ? ? ??
? ? }
//定義"隱藏內容"的函數
? ? function hide(){
? ? ? ? var pre=document.getElementById("con");
? ? ? ? pre.style.display="none";
? ? }
//定義"顯示內容"的函數
? ? function dis(){
? ? ? ? var pre=document.getElementById("con");
? ? ? ? pre.style.display="block";
? ? }
//定義"取消設置"的函數
? ? function repeal(){
? ? ? ? var mychar=confirm("是否取消設置?");
? ? ? ? if (mychar==true)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?pre.removeAttribute("style");
? ? ? ? ? ? ? ?txt..removeAttribute("style");
? ? ? ? ? ?}
? ? }
2019-02-25
兩處代碼錯誤,第一個是txt..removeAttribute("style");多加了一個點,,,,第二個是txt.style.width="300";沒有單位px
2019-02-20
你按鈕ID沒有寫
看我下面的代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.com)</title>
</head>
<body>
?<form>
? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->
? ? <input id="con" type="button" value="改變顏色" ?onClick="color()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數
? ? function color(){
? ? ? ? var pre=document.getElementById("con");
? ? ? ? pre.style.color="red";
? ? }
</script>
</body>
</html>
2019-02-19