我有一个按钮和3个功能。 点击它后改变每个功能 请帮助我。
答案 0 :(得分: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>
&#13;
答案 1 :(得分:0)
试试这个,
将this
传递给函数。它将定位相同的单击按钮元素
function change(that){
that.value="changed"
that.innerHTML="changed" //for inner html change
console.log(that.outerHTML)
}
&#13;
<button id="btn" type="button" onclick="change()">click</button>
&#13;
单行代码
<button id="btn" type="button" onclick="this.innerHTML='changed'">click</button>
&#13;
答案 2 :(得分: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)
}
答案 3 :(得分: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>