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");
}
}
答案 0 :(得分:4)
做这样的事情
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;
}
然后当你想要调用你的函数时,你所要做的就是
action();
action2();
但你想要在调用它们之前检查它们是否已设置
我相信那是你的事后
或做类似的事情
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;
}
然后您不必检查是否已启用只是调用它们,它们将工作或想要取决于它们是否已启用
答案 1 :(得分:0)
如果您不希望函数在特定状态下执行,我会将您的函数包装进行状态检查,然后在处于不适当的状态时返回。
function action(obj){
if(obj.state == <a state you dont want to execute>)
return;
action();
}
function action(){
document.getElementById("movie0").sndToAS("pause");
}