函數取名src可以嗎,代碼應該對的,但試了好幾次居然通不過
隨意取的函數名,好幾次通不過,點擊取消設置沒反應,,,吧src換個名字通過了。換sr就通過了。。折騰了大半夜。這尼瑪是怎么回事???雖然有點鉆牛角尖
?<form>
? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->
? ? <input type="button" onclick="changecolor()" value="改變顏色" > ?
? ? <input type="button" onclick="changewh()" value="改變寬高" >
? ? <input type="button" onclick="hidetxt()" value="隱藏內容" >
? ? <input type="button" onclick="showtxt()" value="顯示內容">
? ? <input type="button" onclick="src()" value="取消設置" >
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數
var char=document.getElementById("txt");
function changecolor()
{char.style.color="red";
char.style.backgroundColor="#ccc";}
//定義"改變寬高"的函數
function changewh()
{char.style.width="300px";
char.style.height="300px";}
//定義"隱藏內容"的函數
function hidetxt(){
? ? char.style.display="none";}
//定義"顯示內容"的函數
function showtxt(){
? ? char.style.display="block";}
//定義"取消設置"的函數
?function src(){
? ? var message=confirm("你確定要重置所有設置么?");
? ? if(message==true)
? ? {? ? ??
? ? ? ? ?char.removeAttribute('style');
? ? }?
? } ? ?
? </script>
</body>
</html>
2015-02-09
src是JS中的關鍵字,在JS中命名變量或者函數的時候,禁止使用JS中的關鍵字來命名