如何更改按钮的名称

时间:2012-09-20 02:26:28

标签: php javascript jquery html joomla

此代码输出为here ....(查看页脚订阅部分)

<?php if(!empty($this->items))foreach($this->items as $level): ?>
<?php
    $formatedPrice = sprintf('%1.02f',$level->price);
    $dotpos = strpos($formatedPrice, '.');
    $price_integer = substr($formatedPrice,0,$dotpos);
    $price_fractional = substr($formatedPrice,$dotpos+1);
?>
    <div class="level akeebasubs-level-<?php echo $level->akeebasubs_level_id ?>">
        <p class="level-title">
            <span class="level-price">
                <?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'before'): ?>
                <span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
                <?php endif; ?>
                <span class="level-price-integer"><?php echo $price_integer ?></span><?php if((int)$price_fractional > 0): ?><span class="level-price-separator">.</span><span class="level-price-decimal"><?php echo $price_fractional ?></span><?php endif; ?>
                <?php if(AkeebasubsHelperCparams::getParam('currencypos','before') == 'after'): ?>
                <span class="level-price-currency"><?php echo AkeebasubsHelperCparams::getParam('currencysymbol','€')?></span>
                <?php endif; ?>
            </span>
            <span class="level-title-text">
                <a href="<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>">
                    <?php echo $this->escape($level->title)?>
                </a>
            </span>
        </p>
        <div class="level-inner">
            <div class="level-description">
                <div class="level-description-inner">
                    <?php if(!empty($level->image)):?>
                    <img class="level-image" src="<?php echo JURI::base()?><?php echo trim(AkeebasubsHelperCparams::getParam('imagedir','images/'),'/') ?>/<?php echo $level->image?>" />
                    <?php endif;?>
                    <?php echo JHTML::_('content.prepare', AkeebasubsHelperMessage::processLanguage($level->description));?>
                </div>
            </div>
            <div class="level-clear"></div>
            <div >
                <button  onclick="window.location='<?php echo JRoute::_('index.php?option=com_akeebasubs&view=level&slug='.$level->slug.'&format=html&layout=default')?>'">
                    <?php echo JText::_('COM_AKEEBASUBS_LEVELS_SUBSCRIBE')?>
                </button>
            </div>
        </div>
    </div>
<?php endforeach; ?>

这是包含该名称的语言文件

COM_AKEEBASUBS_LEVELS_SUBSCRIBE="Subscribe Now"

我想将这三个部分命名为6个月,12个月,24个月

如何更改代码?

1 个答案:

答案 0 :(得分:1)

如果您无法使用PHP获取值,请尝试在页面加载时更改按钮名称的值 这是 JQUERY

 $(document).ready(function){
   $('div.akeebasubs-awesome-description').each(function(
     substription =  $(this).children('H4').html()
     button = $(this).parent().next().children('button')
     $(button).attr(name,substription.split(' ')[0]+'month')
    })
 })

JAVASCRIPT

 divs = document.getElementsByClassName('akeebasubs-awesome-description');
 for (var i in divs){
    divs[i].parentElement.nextElementSibling.children[0].name = divs[i].children[0].innerHTML.split(' ')[0] + 'month'
 }

这将采用H4的文字并将其设为相应的button名称