0

我试图在 Joomla 中显示和隐藏一个 div 但不起作用

这是我要隐藏的 div

<div id="muestra" style="display:none;">
   <? php JToolBarHelper::editListX(); ?>
</div>

我正在调用 javascript 函数

echo $pane->startPanel('<span onclick="mostrar(muestra);">Proveedores</span>','id_panel') ;

我的 javascript 是

function mostrar(id){
if (document.getElementById){ 
var el = document.getElementById(id); 
alert(el);
el.style.display = (el.style.display == 'none') ? 'block' : 'none'; 
}
}
window.onload = function(){
mostrar('muestra');
}
</script>

第一次 el=Object,但第二次是 null 并且从不取值。

有任何想法吗?

4

2 回答 2

0

试试这个

HTML:

<div id="muestra" style="display:none;">
   <?php JToolBarHelper::editListX(); ?>
</div>

PHP:

echo $pane->startPanel('<span onclick="mostrar();">Proveedores</span>','id_panel') ;

Javascript:

<script type="text/javascript">
function mostrar(){
    if (document.getElementById('muestra').style.display == 'none') {
       document.getElementById('muestra').style.display = 'block';
    }
    else {
       document.getElementById('muestra').style.display = 'none';
    }
}
</script>
于 2012-08-21T17:23:55.050 回答
0

尝试用撇号环绕muestra

echo $pane->startPanel('<span onclick="mostrar(\'muestra\');">Proveedores</span>','id_panel');
于 2012-08-22T11:56:37.993 回答