简体   繁体   中英

startPanel with onclick joomla

I'm trying to show and hide a div in Joomla but doesn't work

This is the div I'm trying to hide

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

The I'm calling the javascript function

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

My javascript is

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>

the first time el=Object, but the second one is null and never takes a value.

any ideas?

Give this a try

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM