开发者

onclick not calling javascript function

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜