切换javascript功能 [英] toggle javascript function
本文介绍了切换javascript功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码来启动日志文件:
I'm using this code to start a log file :
function startTail(str) {
if (str== "stop") {
stopTail();
} else {
t= setTimeout("getLog()",1000);
}
}
这被称为使用:
<button id="start" onclick="getLog('start');">
并停止使用:
<button id="stop" onclick="getLog('stop');">
无论如何我可以将其更改为一个可以切换开始/停止的按钮吗?
Is there anyway I can change this to one button that will toggle start / stop ?
推荐答案
尝试:
<button id="start" value="Toggle Log" onclick="getLog('start', this);">
function startTail(str, element) {
if (str == "stop") {
stopTail();
element.setAttribute('onclick', "getLog('start', this);");
} else {
element.setAttribute('onclick', "getLog('stop', this);");
}
}
这篇关于切换javascript功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文