startPanel with onclick joomla

startPanel with onclick joomla

本文关键字:joomla onclick with startPanel      更新时间:2023-09-26

我试图在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并且从不取值。

有什么想法吗?

试试

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>

尝试用撇号包围muestra

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