angular.js - 一个Angularjs的坑
phpcn_u1582
phpcn_u1582 2017-05-15 16:58:49
0
2
501

情景一:

 var p_NormalStatus = document.getElementById("NormalStatus");//p1
 var p_LockStatus = document.getElementById("LockStatus");//p2

 function getData(){  
    p_NormalStatus.style.display = "none";//1
    p_LockStatus.style.display = "block";//2
 }

第一次加载页面的时候 执行getData函没问题
返回后再次进来 代码1,2都执行了,可是2个p都显示了,也就是代码没起作用;

情景二:

 function getData(){  
    document.getElementById("NormalStatus").style.display = "none";//1
    document.getElementById("LockStatus").style.display = "block";//2
 }

这样就ok了!

求教大神解释下为什么会这样?!

phpcn_u1582
phpcn_u1582

reply all(2)
为情所困

In scenario 1, when codes 1 and 2 are executed, the page has not loaded the two DOM objects, and then cached two empty DOM objects. Naturally, there will be no value when executing getData. Moreover, your problem has nothing to do with angularjs. , do I still need to write like you do when using ng?

给我你的怀抱

First of all, when you encounter a problem, you need to interrupt and check what is causing it.
Then, use classes to change the style instead of redrawing intermittently.
Finally, the specific problem and the specific environment include your loading method function. Execution environment

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template