2017-07-07 90 views

回答

1
i dont understand your question, i think you mean like this one button 

試一試,使用document.getElementById

<button id="btn" type="button" onclick="document.getElementById('btn').innerHTML = 'Hey There'">Try it</button>

+0

我有1個按鈕名爲「btn_big」和3個函數。當我點擊第一次它改變到第二個功能,如果我再次點擊它改變爲最後一個功能。 – Viroth

+0

'請把你的代碼部分,我們可以很容易地解決這個問題'並使用'代碼片段'把它放在你的代碼它 – core114

+0

我不知道如何javascript – Viroth

0

試試這個,

與函數傳遞this。它會針對同一個點擊的按鈕元素

function change(that){ 
 
that.value="changed" 
 
that.innerHTML="changed" //for inner html change 
 
console.log(that.outerHTML) 
 
}
<button id="btn" type="button" onclick="change()">click</button>

對於線路碼

<button id="btn" type="button" onclick="this.innerHTML='changed'">click</button>

0
<button type="button" onclick="a()">click</button> 

的javascript

var a = (function() { 
    var clicked = 0; 
    return function() { 
     clicked++; 
     if (clicked == 1) f1(); // improve this part 
     if (clicked == 2) f2(); 
     if (clicked == 3) f3(); 
    } 

})() 

function f1() { 
    alert(1) 
} 

function f2() { 
    alert(2) 
} 

function f3() { 
    alert(3) 
} 

demo

0
function change(that){ 
     that.value="Changed" 
     that.innerHTML="Changed" 
} 

<button id="btn" type="button" onclick="change(this)">click</button 


     or 


<button id="btn" type="button" onclick = "this.innerHTML = 'Changed'" > click </button> 

<button id="btn" type="button" onclick = "document.getElementById('btn').innerHTML = 'Changed' "> Try it </button>