toggle javascript function
问题 I'm using this code to start a log file : function startTail(str) { if (str== "stop") { stopTail(); } else { t= setTimeout("getLog()",1000); } } This is called using : <button id="start" onclick="getLog('start');"> and stopped using : <button id="stop" onclick="getLog('stop');"> Is there anyway I can change this to one button that will toggle start / stop ? 回答1: Try: <button id="start" value="Toggle Log" onclick="getLog('start', this);"> function startTail(str, element) { if (str == "stop") {