1

我正在尝试根据 php 函数中的 div id 隐藏或显示 div。我无法使它工作,请帮助我。

Javascript:

<script>
showOrHide(id) {
    var elem=getElementById(id);
    if(elem.style.visibility="hidden")
        elem.style.visibility="visible";
    else
        elem.style.visibility="hidden";
}
</script>

PHP 脚本:

<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid) {
?>
    <a href="javascript:showOrHide(<?php echo $divid; ?>)">More links</a>
    <div id="<?php echo $divid ?>" style="visibility:hidden;">
    </div>
<?php } ?>
4

3 回答 3

4

这是您的功能的清理版本。

function showOrHide(id) {

  var elem = document.getElementById(id);

  elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
}
于 2013-04-09T04:58:14.107 回答
0
<script>
function showOrHide(id){
 var elem = getElementById(id);
 if(elem.style.visibility=="hidden"){
  elem.style.visibility="visible";
 } else {
  elem.style.visibility="hidden";
 }
}
</script>
<?php
function display_link($link_id,$upvote_array,$downvote_array,$divid)
{
?>
<a href="javascript:showOrHide('<?php echo $divid; ?>')">More links</a>
<div id="<?php echo $divid ?>" style="visibility:hidden;">
</div>

1 - 可见性 == '隐藏'

2 - 失踪; 在可见性=“可见”和“隐藏”之后

3 - href="javascript:showOrHide('')" - 在你的 javascript 函数中缺少 ''

于 2013-04-09T04:59:37.837 回答
-1

试试这个

 <script>
    function showOrHide(id){
     var elem = document.getElementById(id);

  elem.style.visibility = (elem.style.visibility === 'hidden')? 'visible' : 'hidden';
    }

    </script>
    <?php
    function display_link($link_id,$upvote_array,$downvote_array,$divid)
    {
    ?>
    <a  href="javascript:showOrHide(<?php echo $divid; ?>)">More links</a>
    <div id="<?php echo $divid ?>" style="display:hidden;">
    </div>
    <?php
    }
    ?>
于 2013-04-09T04:57:31.357 回答