寫完了phpstorm
寫完了
<form>
? ?<!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->
? ?<input type="button" value="改變顏色" onclick="changeColor()">
? ?<input type="button" value="改變寬高" onclick="changeHw()">
? ?<input type="button" value="隱藏內容" onclick="dis()">
? ?<input type="button" value="顯示內容" onclick="xS()">
? ?<input type="button" value="取消設置" onclick=" qX()">
</form>
<script type="text/javascript">
? ?//定義"改變顏色"的函數
? ?var txt=document.getElementById("txt");
? ?function changeColor(){
? ? ? ?var txt=document.getElementById("txt");
? ? ? ?txt.style.color="red";
? ? ? ?txt.style.backgroundColor="blue"
? ?}
? ?//定義"改變寬高"的函數
? ?function changeHw(){
? ? ? ?var txt=document.getElementById("txt");
? ? ? ?txt.style.width="300px";
? ? ? ?txt.style.height ="500px";
? ?}
? ?//定義"隱藏內容"的函數
? ?function dis(){
? ? ? ?var txt=document.getElementById("txt");
? ? ? ?txt.style.display="none";
? ?}
? ?//定義"顯示內容"的函數
? ?function xS(){
? ? ? ?var txt=document.getElementById("txt");
? ? ? ?txt.style.display="block";
? ?}
? ?//定義"取消設置"的函數
? ?function qX(){
? ? ? ?var message=confirm("你確定要重置所有設置么?");
? ? ? ?if(message==true){
? ? ? ? ? ?txt.removeAttribute('style');
? ? ? ?}
? ?}
2015-12-18
取消設置應該這樣寫
?function qX(){
var txt=document.getElementById("txt"); ? ? ?
var message=confirm("你確定要重置所有設置么?");
? ? ? ?if(message==true){
? ? ? ? ? ?txt.removeAttribute('style');
? ? ? ?}
? ?}