I have written this javascript
<script type="text/javascript">
function toggle(user_id) {
e=document.getElementById('toggleUserinfo_'+user_id);
a=document.getElementById('displayUserinfo_'+user_id);
if (e.style.display=='block') {
e.style.display='none'; a.innerHTML='show';
} else {
e.style.display='block'; a.innerHTML='hide';
}
}
</script>
but its working fine on one page not working on other. The same file开发者_运维知识库 is used on both, any ideas?
The chance is that in the other page the elements don't exist for example the "toggleUserInfo_" and "displayUserInfo_", check to see whether they are available or not.
Another problem that I see is "e" and "a" both the variables are global( missing var keyword ) which is not good.
did you try by putting debugger; and debugging the code
and also if possible use === for comparison
If possible can you give more code to understand the problem
Missing elements
It's highly likely that you don't have those two elements on the other page either.
toggleUserinfo_ID
toggleUserinfo_ID
ID being user_id.
Use Firbug
When having Javascript problems, majority of web developers use Firefox with Firebug extension that alows you to set breakpoints and debug the whole javascript functionality of the page.
Set a breakpoint on the first lone of your toggle
function and see what's going on.
精彩评论