How to enable and disable javascript functions?
if(tmpStr == tmp+value)
{
i=1;
action = null;
action2 = null;
}
if(tmpStr1 == tmp+value)
{
i=0;
action();//not working
action2();//not working
}
for(i;i<=14; i++)
{
if(tmp!="movie"+i)
{
document.getElementById("movie"+i).sndToAS("resume");
}
}
}
function action()
开发者_开发问答 {
document.getElementById("movie0").sndToAS("pause");
}
function action2()
{
if(tmp != "movie0")
{
document.getElementById("movie0").sndToAS("pause");
}
}
Do something like this
function actionFunc(){
document.getElementById("movie0").sndToAS("pause");
}
function action2Func()
{
if(tmp != "movie0"){
document.getElementById("movie0").sndToAS("pause");
}
}
window.action = actionFunc;
window.action2 = action2Func;
if(tmpStr == tmp+value)
{
id=1;
window.action = null;
window.action2 = null;
}
if(tmpStr1 == tmp+value)
{
id=0;
window.action = actionFunc;
window.action2 = action2Func;
}
Then when you want to call your functions all you have to do is
action();
action2();
but your going to want to check if the are set before calling them
I believe thats what your after
or do something like this
function action(){
if (window.actionEnabled)
{
document.getElementById("movie0").sndToAS("pause");
}
}
function action2()
{
if (window.action2Enabled)
{
if(tmp != "movie0"){
document.getElementById("movie0").sndToAS("pause");
}
}
}
window.actionEnabled = true;
window.action2Enabled = true;
if(tmpStr == tmp+value)
{
id=1;
window.actionEnabled = false;
window.action2Enabled = false;
}
if(tmpStr1 == tmp+value)
{
id=0;
window.actionEnabled = true;
window.action2Enabled = true;
}
then you don't have to check if the are enabled just call them and they will work or want depending on if they are enabled
If you don't want a function to execute when in a particular state, I would wrap your function do a state check and then a return if in an inappropriate state.
function action(obj){
if(obj.state == <a state you dont want to execute>)
return;
action();
}
function action(){
document.getElementById("movie0").sndToAS("pause");
}
just declare a global variable
var stopfunction=false;
and as a first line in your function
if (stopfunction) return;
精彩评论