課程
/前端開發
/JavaScript
/JavaScript入門篇
reset函數運行不了,是什么鬼?????
2018-10-26
源自:JavaScript入門篇 4-1
正在回答
reset是關鍵字,不能用否則有沖突,你可以改成其他名字,這種簡單而且涉及操作的英文如果出問題了,實在找不到原因基本上都可以注意一下是不是關鍵字沖突。
改一下函數名就可以了,不能用reset,會有沖突的。
其他的都能用就reset不行
<input type="button" onclick="changecolor()" value="改變顏色" >??
? ? <input type="button" onclick="changewidth()" value="改變寬高" >
? ? <input type="button" onclick="content()" value="隱藏內容" >
? ? <input type="button" onclick="display()" value="顯示內容" >
? ? <input type="button" onclick="reset()" value="取消設置" >
? </form>
? <script type="text/javascript">
? ? var text=document.getElementById('con');
? ? var box=document.getElementById('txt');
? ? function changecolor(){
? ? ? ? text.style.color='red';
? ? ? ? box.style.backgroundColor='gray';
? ? }
? ? function changewidth(){
? ? ? ? var box=document.getElementById('txt');
? ? ? ? box.style.width='200px';
? ? ? ? box.style.height='500px';
? function content(){
? ? ? box.style.display="none";
? }
? function display(){
? ? ? box.style.display="block";
? ? function reset(){
? ? ? ? var srs = confirm("確認取消設置?");
? ? ? ? if (srs==true)
? ? ? ? {
? ? ? ? ? ? box.style.color = "black";
? ? ? ? ? ? box.style.backgroundColor = "white";
? ? ? ? ? ? box.style.width = orignWidth;
? ? ? ? ? ? box.style.height = orignHeight;
? ? ? ? ? ? box.style.display = "block";
? ? ? ? }
? </script>
</body>
</html>
舉報
JavaScript做為一名Web工程師的必備技術,本教程讓您快速入門
2 回答reset函數不運行,求解
5 回答函數運行不了
1 回答reset不能為函數名嗎?
1 回答reset不行,好像reset是關鍵詞
3 回答為什么將取消設置的函數起名為 reset 就不行呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-11-01
reset是關鍵字,不能用否則有沖突,你可以改成其他名字,這種簡單而且涉及操作的英文如果出問題了,實在找不到原因基本上都可以注意一下是不是關鍵字沖突。
2018-10-26
2018-10-26
其他的都能用就reset不行
2018-10-26
<input type="button" onclick="changecolor()" value="改變顏色" >??
? ? <input type="button" onclick="changewidth()" value="改變寬高" >
? ? <input type="button" onclick="content()" value="隱藏內容" >
? ? <input type="button" onclick="display()" value="顯示內容" >
? ? <input type="button" onclick="reset()" value="取消設置" >
? </form>
? <script type="text/javascript">
? ? var text=document.getElementById('con');
? ? var box=document.getElementById('txt');
? ? function changecolor(){
? ? ? ? text.style.color='red';
? ? ? ? box.style.backgroundColor='gray';
? ? }
? ? function changewidth(){
? ? ? ? var box=document.getElementById('txt');
? ? ? ? box.style.width='200px';
? ? ? ? box.style.height='500px';
? ? }
? function content(){
? ? ? box.style.display="none";
? }
? function display(){
? ? ? box.style.display="block";
? }
? ? function reset(){
? ? ? ? var srs = confirm("確認取消設置?");
? ? ? ? if (srs==true)
? ? ? ? {
? ? ? ? ? ? box.style.color = "black";
? ? ? ? ? ? box.style.backgroundColor = "white";
? ? ? ? ? ? box.style.width = orignWidth;
? ? ? ? ? ? box.style.height = orignHeight;
? ? ? ? ? ? box.style.display = "block";
? ? ? ? }
? ? }
? </script>
</body>
</html>