如何在生成的代码中添加属性?

时间:2016-06-10 01:17:17

标签: javascript php jquery html joomla

我有一个代码

FoxHtmlElem::create('div')
    ->attr('id', $current->getBoxId())
    ->classes("fox-item fox-item-submit fox-item-submit-{$current->get('alignment')} control-group")
    ->classes($current->get('classes'))
        ->append(FoxFormRender::render('label_collapsed'))
        ->append(FoxHtmlElem::create('div')
            ->classes('controls')
                ->attr('style', "{$current->getStyleWidth()}{$current->getStyleHeight()}")
        ->append(FoxHtmlElem::create('button')
            ->classes('btn btn-success submit-button')
            ->tooltip($current->get('submit.tooltip'))
            ->attr('type', 'submit')
        ->append(FoxHtmlElem::create('span')
        ->append(FoxHtmlElem::create('span')
            ->classes($current->getIconClass('submit'))
            ->attr('style', $current->getIconStyle('submit'))
            ->text($current->get('submit.label')))))
            ->conditional($current->get('reset.enable'), function () use($current)
{
    return FoxHtmlElem::create('button')
        ->classes('btn btn-danger reset-button')
        ->tooltip($current->get('reset.tooltip'))
        ->attr('type', 'reset')
        ->append(FoxHtmlElem::create('span')
        ->append(FoxHtmlElem::create('span')
        ->classes($current->getIconClass('reset'))
        ->attr('style', $current->getIconStyle('reset'))
        ->text($current->get('reset.label'))));
}))->show();

此代码生成html

<div id="fox-m138-submit-box" class="fox-item fox-item-submit fox-item-submit-fields control-group">
    <span class="control-label collapsed"></span>
<div class="controls">
    <button type="submit" class="btn btn-success submit-button">
        <span>
            <span>Отправить</span>
        </span>
    </button>
</div>

我需要为按钮添加属性:

onclick="yaCounterXXXXXX.reachGoal('ORDER'); return true;"

是joomla fox联系表。对不起自动代码。我按原样复制并粘贴了它。

2 个答案:

答案 0 :(得分:0)

使用click()功能。

$(element).click(function(){});

我从未使用过Joomla,但为此使用jQuery应该没问题。

答案 1 :(得分:0)

疯狂猜测,添加此

->attr('onclick', 'yaCounterXXXXXX.reachGoal("ORDER"); return true;')

以下代码后

->attr('type', 'reset')