這是可能的,在Magento中,創建兩個或多個相關的選擇? 例如國家/地區 我嘗試使用jQuery,但似乎不起作用。 問候相關select在Magento中我該怎麼做
我嘗試用這個代碼:在Mymodule中輸出
應用程序/設計/前端/基/默認/模板/ 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>
在我的應用程序/設計/前端/基/默認/模板/頁/ 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>
在我的應用程序/代碼/本地/ frontname/mymodule中/ SQL/mysql4安裝-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();
文件result.php
<?php
include_once 'option.class.php';
$obj = new Option();
$obj->ShowResult();
?>
文件selection.php
<?php
include_once 'option.class.php';
$obj = new Option();
$obj->ShowNazioni();
?>
的第一選擇似乎與區域表的內容,但是,如果我點擊的choise一個區域,第二選擇不會在其內部加載數據。
編輯:解決! 我改變我的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的字!
把一些代碼。你已經嘗試了什麼? – Guerra
我已發佈代碼!你可以幫我嗎? – Luigi