jquery点击 - 无法看到为什么点击赢了工作

时间:2015-03-11 18:58:19

标签: jquery

希望有人能够看到我能在这里做什么 - jquery正在被加载到头部。前提是能够从提供的列表中选择颜色样本。我已经在下面添加了渲染的html来说明正确的填充值。

<script>
// choose default colour subcolors
jQuery(document).ready(function(){
    jQuery('ul.colourcategory_swatch li[data-value=<?php echo   
$defaultColorCategory ?>]').click()
});
</script>

 <ul class="colourcategory_swatch">
 <?php $attribute =   
Mage::getModel('eav/config')->getAttribute('catalog_product', 
'colourcategory'); ?>
 <?php foreach ($attribute->getSource()->getAllOptions(true, true) as  
$option): 

if(!empty($option['value'])):$backgroundColor = split('#' , 
$option['label'] ); ?>
                                           <?php 
                                               $attId = 
$attribute->getId();
                                               $filter_id = 
$option['value'];
                                               $subcolors = 
Mage::getStoreConfig('color_selector_plus/layerednavopts
/filter_'.$attId.'_'.$filter_id.'_layereds', Mage::app()->getStore());
                                           ?>
                                           <li data-subcolors="<?= 
$subcolors ?>" data-value="<?= $option['value']?>" style="background: 
#<?= $backgroundColor[1]?>" title="<?= $option['label']?>"
                                           <?php 
if($defaultColorCategory == $option['value']):?> class="selected"<?php 
endif;?>></li>
                                       <?php endif;endforeach; ?>
                                   </ul>
Rendered html:
<div class="input-box">
<input id="colourcategory" class="input-text required-entry error"    
type="hidden" value="12" name="product[colourcategory]">
<ul class="colourcategory_swatch">
<li class="selected" title="Black #1C0F0A" style="background: #1C0F0A" 
data-value="12" data-subcolors="36"></li>

1 个答案:

答案 0 :(得分:1)

语法必须是:

$('your selector').click(function() {/*do something here*/});

所以难怪它什么都不做。