-1

有可能,在 Magento 中,创建两个或更多相关的选择吗?例如,我尝试使用 jQuery 的国家/地区,但似乎不起作用。此致

我尝试使用此代码:在 Mymodule 输出中

app/design/frontend/base/default/template/mymodule/mymodule.phtml

   <div id="continenti">
<?php
include_once 'option.class.php';
$obj = new Option();
$obj->ShowContinenti();
?>
</div>

<div id="nazioni">
Seleziona una nazione:<br>
<select id="sel_nazioni" name="sel_nazioni"><option value="no">Scegli...</option>
</select>
</div>

<div id="result"></div>

在我的 app/design/frontend/base/default/template/page/html/head.phtml

<script type="text/javascript" src="./jquery/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$('#sel_continenti').change(function(){

            var cont = $('#sel_continenti').attr('value');

            $.post("selection.php", {id_cont:cont}, function(data){
            $("#sel_nazioni").empty();
            $("div#result").empty();
            $("#sel_nazioni").prepend(data);
            });
            });

$('#sel_nazioni').change(function(){

            var id_naz = $('#sel_nazioni').attr('value');

            $.post("result.php", {id:id_naz}, function(data){
            $("div#result").empty();
            $("div#result").prepend(data);
            });
            });

});
</script>

在我的 app/code/local/frontname/mymodule/sql/mysql4-install-0.1.0

<?php
$installer = $this;

$installer->startSetup();

$installer->run("

    -- DROP TABLE IF EXISTS {$this->getTable('continenti')};
    CREATE TABLE {$this->getTable('continenti')} 
          `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
          `continente` VARCHAR(40) NOT NULL,
          PRIMARY KEY  (`id`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

        INSERT INTO `continenti` (`id`, `continente`) VALUES
        (1, 'Europa'),
        (2, 'Africa'),
        (3, 'Sud America');

        -- DROP TABLE IF EXISTS {$this->getTable('nazioni')};
    CREATE TABLE {$this->getTable('nazioni')} 
          `id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
          `id_cont` INT(2) UNSIGNED NOT NULL,
          `nazione` VARCHAR(50) NOT NULL,
          PRIMARY KEY  (`id`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

        INSERT INTO {$this->getTable('nazioni')} (`id`, `id_cont`, `nazione`) VALUES
        (1, 1, 'Spagna'),
        (2, 1, 'Francia'),
        (3, 1, 'Italia'),
        (4, 1, 'Germania'),
        (5, 1, 'Belgio'),
        (6, 2, 'Egitto'),
        (7, 2, 'Marocco'),
        (8, 2, 'Tunisia'),
        (9, 2, 'Uganda'),
        (10, 3, 'Argentina'),
        (11, 3, 'Cile'),
        (13, 3, 'Brasile');

    ")

    ;




     $installer->endSetup();

文件结果.php

<?php
include_once 'option.class.php';
$obj = new Option();
$obj->ShowResult();
?>

文件选择.php

<?php
include_once 'option.class.php';
$obj = new Option();
$obj->ShowNazioni();
?>

第一个选择显示区域表的内容,但是,如果我单击并选择一个区域,第二个选择不会在其内部加载数据。

编辑:解决!我改变了我的head.phtml

<script type="text/javascript" src="./jquery/jquery-1.3.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {

jQuery('#sel_continenti').change(function(){

            var cont = jQuery('#sel_continenti').attr('value');

            jQuery.post("selection.php", {id_cont:cont}, function(data){
            jQuery("#sel_nazioni").empty();
            jQuery("div#result").empty();
            jQuery("#sel_nazioni").prepend(data);
            });
            });

jQuery('#sel_nazioni').change(function(){

            var id_naz = jQuery('#sel_nazioni').attr('value');

            jQuery.post("result.php", {id:id_naz}, function(data){
            jQuery("div#result").empty();
            jQuery("div#result").prepend(data);
            });
            });

});
</script>

我用 jQuery word 改变 $ !

4

1 回答 1

0

Magento 在结帐地址 phtmls 中已经有了这种选择,只是它使用了 Prototype。

<div class="field">
<label for="billing:region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
    <select id="billing:region_id" name="billing[region_id]" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
        <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
    </select>
    <script type="text/javascript">
    //<![CDATA[
        $('billing:region_id').setAttribute('defaultValue',  "<?php echo $this->getAddress()->getRegionId() ?>");
    //]]>
    </script>
    <input type="text" id="billing:region" name="billing[region]" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
</div>

<div class="field">
<label for="billing:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
    <?php echo $this->getCountryHtmlSelect('billing') ?>
</div>

var billingRegionUpdater = new RegionUpdater('billing:country_id', 'billing:region', 'billing:region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'billing:postcode');
于 2013-08-22T13:52:58.883 回答