I'm having a simple issue with calling a javascript function. I've been playing with this for hours and I can't see the problem. Hopefully another perspective can help.
in the of my php file:
<script type="text/javascript">
function showShareDiv(objid){
var div = document.getElementById('share'+objid);
if (div.style.display=='none'){
div.style.display='block';
}
else{
div.style.display='none');
}
}
</script>
This is just to show/hide a div with name "share"+number (eg. share104). When I look at the source the $obj->id correctly names the div and function onclick name.
Here is the button:
<div id="sharebutton" style="width:100%;" onclick="showShareDiv('<?=$obj->id?>');">
<center>Share</center>
</div>
&l开发者_如何学编程t;div id="share<?=$obj->id?>" style="display:none;">
SHARE BUTTONS GO HERE
</div>
Any help is appreciated.
You have an extra )
function showShareDiv(objid){
var div = document.getElementById('share'+objid);
if (div.style.display=='none'){
div.style.display='block';
}
else{
div.style.display='none'; //had a `)` here
}
}
Now it works: http://jsfiddle.net/maniator/eHMZR/
You can put an alert('test') in function, to see if function is called.
精彩评论