magento - 更改所选 radio 上的文本

标签 magento select checkbox

您好,我需要有关此脚本的一些帮助。我需要在选择单选标签时在产品代码 div 上显示 sku。

有一些行 $j("input#attribute 和 input:radio 我无法修复

实际上,这可以让 sku 具有可选择的尺寸或颜色。

php代码

<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <dl>
    <?php foreach($_attributes as $_attribute): ?>
        <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>

            <div class="input-box">
                <?php $configs = $this->getRegularConfig()?>
                <?php foreach($configs['attributes'] as $config):?>
                    <?php foreach($config['options'] as $value):?>
                        <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
                        <label class="label-radio-configurable" id="<?php echo (float)$value['price'] + (float) $_product->getPrice();?>">
                        <input type="radio" name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]"
                                id="attribute<?php echo $_attribute->getAttributeId() ?>"
                                class="validate-custom-configurable"
                                value="<?php echo $value['id']?>"/>
                            <?php echo $value['label']?> (+ $<?php printf("%.2f", $value['price'])?>)
                        </label>
                    <?php endforeach;?>
                <?php endforeach;?>
                 </dd>
              </div>

    <?php endforeach; ?>
    </dl>
<?php endif;?>

JS脚本

<div id="productcode"></div>

<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
?>

<script type="text/javascript">

var Skus =new Array();

<?php
$count = 1;
$itemId = array();
foreach($col as $simple_product){
$itemId[] = array($simple_product->getSelectLabel() => $simple_product->getSku());
}

foreach($itemId as $val){
foreach($val as $k => $v){
echo 'Skus['.$count.'] = "'.$v.'";'. "\n";
$count++;
}
};

?>

$j(document).ready(function(){

$j("#productcode").html("Code: " +Skus[1]);

$j("input#attribute<?php echo $_attribute->getAttributeId() ?>").change(function(){
var position = $j("#attribute<?php echo $_attribute->getAttributeId() ?> input").index($j("#attribute<?php echo $_attribute->getAttributeId() ?> input:radio));

$j("#productcode").html(Skus[position] ? "Code: " +Skus[position] : "Code: " +Skus[1]);
});

});

</script>

最佳答案

$j(document).ready(function()

使用jQuery代替j

由于jquery冲突

还有

请在您的 jquery 文件中写入以下代码

jQuery.noConflict();

关于magento - 更改所选 radio 上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400155/

相关文章:

php - Magento/Zend Framework 中的内存泄漏

php - 如何在 foreach 循环中选择一个特定选项

php - 动态复选框和选择框

html - ipad 上带有 div 的复选框标签不可点击

javascript 使用输入类型复选框进行加法和减法

layout - 如何 'force' Magento加载不同的布局

php - Magento:拦截所有外发电子邮件

magento - 卸载 Magento 扩展及其关联的数据库表和设置

php - 更新值而不删除其他值并删除 PHP CONCAT 列中的现有值

Android Sqlite FTS3 如何选择开头的单词?