下拉聯動有關問題

來源:互聯網
上載者:User
下拉聯動問題
省和市的聯動,省市的內容都是從資料庫裡取出來的,
現在是選擇了省,對應的市出來之後,省又回到最初的值,選擇的值儲存不住,因為畫面又重新整理了。
有什麼辦法能儲存住省,或者不用畫面重新整理?

下面是部分代碼















//初期,綁定省
public function action()
{

$retArr=array();
//省取得
$retArr=$this->qaModel->getProvince();

if(count($retArr)>0)
{
foreach ($retArr as $key => $i)
{
$provinceList[$i["PROVINCE_KEY"]] = $i["PROVINCE_NAME"];
}
}
//取得したデータを設定
$this->_smarty->assign("provinceList", $provinceList);

// お問い合わせ畫面を表示する 這步顯示畫面submit.html
$this->_smarty->render($this->_language."/submit");
}

//聯動,綁定市
public function cityAction()
{
$province_key=$this->_context->query("province_key", "");

$this->log->info($province_key);


$retArr=array();
//省取得
$retArr=$this->qaModel->getCity($province_key);

if(count($retArr)>0)
{
foreach ($retArr as $key => $i)
{
$cityLis[$i["CITY_KEY"]] = $i["CITY_NAME"];
}
}

//取得したデータを設定
$this->_smarty->assign("cityList", $cityLis);

// お問い合わせ畫面を表示する 這步再回到初期,這樣的話省就重新綁定了
$this->action();
}


------解決方案--------------------
你這亂七八糟的日文是什麼網站?日本的? 日本用都道府縣 市區町村。
建議用ajax做。這樣速度快點 不用每次重新整理。

都道府県 {html_options options=$res.m_states selected=$res.mst_state_id------解決方案--------------------default:""}
市區町村 {html_options options=$res.m_city selected=$res.mst_city_id------解決方案--------------------default:""}

function Linkage(obj,id) {
var param = {};
param.mst_state_id = obj;
$.ajax({
type : "POST"
, url : " php"
, data : $.param(param)
, dateType : "xml"
, success : function(xml) {
var selects = $("select[id="+id+"]");
$(selects)[0].length=0;
$(selects)[0].options[0]=new Option("市區町村","0");
$("category", xml).each(function(){
var id = $("id", this).text();
var name = $("name", this).text();
$(selects)[0].options.add(new Option(name, id));
});
}
});
}

url : "php" 這裡是接受都道府縣的id的php 注意路徑
這個php 最後輸出

$str = "";
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.