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>