Javascript 如何在joomla按钮中添加onclick事件

Javascript 如何在joomla按钮中添加onclick事件,javascript,php,joomla,Javascript,Php,Joomla,我的站点中有一个签出按钮的代码。如何在此中添加onclick事件?可以使用JDocument在组件或模块的显示模板中直接声明JavaScript代码块 if($this->params->get('show_cart_proceed',1)) { echo $this->cart->displayButton(JText::_(''),'checkout',$this->params,hikashop_completeLink('checkout'.$url_i

我的站点中有一个签出按钮的代码。如何在此中添加onclick事件?

可以使用JDocument在组件或模块的显示模板中直接声明JavaScript代码块

if($this->params->get('show_cart_proceed',1)) {
  echo $this->cart->displayButton(JText::_(''),'checkout',$this->params,hikashop_completeLink('checkout'.$url_itemid),'');
}
或者,如果您有外部javascript,那么您可以在那里运行,如果您没有使用

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration('
    window.event("domready", function() {
        document.getElementById('buttonId').onclick = function () {};
    });
');
?>
提及

<?php
$document = JFactory::getDocument();
$document->addScript('/media/system/js/sample.js');
?>