Table of Contents
回复讨论(解决方案)

下拉联动问题

Jun 23, 2016 pm 01:55 PM
drop down Linkage

省和市的联动,省市的内容都是从数据库里取出来的,
现在是选择了省,对应的市出来之后,省又回到最初的值,选择的值保存不住,因为画面又刷新了。
有什么办法能保存住省,或者不用画面刷新?

下面是部分代码

<p class="Fld"><label class="label" for="state">省</label><span class="control"><select id="state" class="req1" name="Prefecture"  onchange="getCitySubmit();"> 		<!--{html_options options=$provinceList}-->        </select></span></p><p class="Fld"><label class="label" for="city">市</label><span class="control"><select id="city" class="req1" name="City" >            <!--{html_options options=$cityList}-->        </select></span></p>
Copy after login

//初期,绑定省 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();    }
Copy after login


回复讨论(解决方案)

日文? 不刷新很定要ajax传值呀

参考Ajax:

<?php#action.phpif(isset($_GET['id'])){	$sql="select * from table where id=".$_GET['id'];	$res=mysql_query($sql);	if(!$res) die("SQL: {$sql} <br>Error:".mysql_error());	if(mysql_affected_rows() > 0){		$arrMenu=array();		while($rows = mysql_fetch_array(MYSQL_ASSOC)){			array_push($arrMenu,$rows);		}	}	mysql_close();	if(!empty($arrMenu)){		echo "<select name='menu2'>";		foreach($arrMenu as $item2){			echo "<option value='{$item2['id']}'>{$item2['name']}</option>";		}		echo "</select>";	}}?>
Copy after login

<form name="frm"><select name="s1" onChange="redirec(this.value)"> <option selected>请选择</option> <option value="1">天文</option> <option value="2">地理</option> <option value="3">算术</option></select><div id="s2"></div></form><script>$("select").live("change",function(){			$.ajax({				  type: "GET",				  url: "action.php",				  data: "id="+$(this).val(),				  cache: false,				  success: function(text){				    $("#show").append(text);				  }			});		});
Copy after login

这是ajax的事。

こんにちは。


你要把选中的省市id传一下。

こんにちは。


你要把选中的省市id传一下。



弄是弄好了,还是刷新的。

你这乱七八糟的日文是什么网站?日本的? 日本用都道府县 市区町村。
建议用ajax做。这样速度快点 不用每次刷新。




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 = "";
foreach ($m_state2 as $key => $val) {
$str .= "" . $key . "" . $val . "";
}
header("Content-Type:text/xml; charset=utf-8");
echo ''.mb_convert_encoding($str, "utf-8").'';
exit;

你这乱七八糟的日文是什么网站?日本的? 日本用都道府县 市区町村。
建议用ajax做。这样速度快点 不用每次刷新。



{html……



是中国的网站,有三种语言版本

你这乱七八糟的日文是什么网站?日本的? 日本用都道府县 市区町村。
建议用ajax做。这样速度快点 不用每次刷新。


mst_state_id 是你的select的属性。这个随便起名字,只要能统一就行。改成你的state也可以。

引用 2 楼 的回复:

参考Ajax:
PHP code
#action.php
if(isset($_GET['id'])){
$sql="select * from table where id=".$_GET['id'];
$res=mysql_query($sql);
if(!$res) die("SQL: {$sql}
Error:".mysq……



<form name="frm"><select name="s1" onChange="record(this.value)"> <option selected>请选择</option> <option value="1">天文</option> <option value="2">地理</option> <option value="3">算术</option></select><div id="show"></div></form><!--Ajax属于js应用,当然要放在script标签中,两种写法jQuery和JavaScript--><script>//Ajax-jquery,必须加载jQuery库:jquery_1.4.2.jsdocument.write("<script src='jquery_1.4.2.js'></script>");$("select").live("change",function(){			$.ajax({				  type: "GET",				  url: "action.php",				  data: "id="+$(this).val(), //这里的id获取的是select选中的value值				  cache: false,				  success: function(text){				    $("#show").append(text);				  }			});		});//Ajax-javascriptvar xmlHttp;	function createXMLHttpRequest() {		if(window.XMLHttpRequest) {			xmlHttp = new XMLHttpRequest();		} else if (window.ActiveXObject) {			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");		}	}	function record(id){  //这里的id获取的是select选中的value值		createXMLHttpRequest();		url = "action.php?id="+id+"&ran="+Math.random();		method = "GET";		xmlHttp.open(method,url,true);		xmlHttp.onreadystatechange = show;  //利用回调函数返回php处理后的数据		xmlHttp.send(null);	}	function show(){		if (xmlHttp.readyState == 4){			if (xmlHttp.status == 200){				var text = xmlHttp.responseText;				document.getElementById("show").innerHTML = text;  //这里将php返回的数据写入html中id=show的标签中			}else {				alert("response error code:"+xmlHttp.status);			}		}	}</script>
Copy after login

引用 8 楼 的回复:

引用 2 楼 的回复:

参考Ajax:
PHP code
#action.php
if(isset($_GET['id'])){
$sql="select * from table where id=".$_GET['id'];
$res=mysql_query($sql);
if(!$res) die("SQL: {$sql} ……




我只是想联动一下,怎么会这么麻烦呢,我都看不懂啊,拷进去也改不对。。。

“jquery_1.4.2.js”是不是还需要这个文件,还是只要有这句话就可以了?

好痛苦啊

你想用ajax就要加载jquery文件的。
需要那个文件 要把它加载到你的html文件里面 写对路径。


写在head头里就行。

这个能测试,至于能懂多少就看你的了,先会用,再慢慢琢磨

<?php/* Created on [2012-7-4] Author[Newton] */#Ajax_select.php 此php和html要分为两个页面if(isset($_GET['id'])){	#$arrMenu数组可以是数据库查询的结果数组等任意二维数组	$arrMenu=array(		array('id'=>3,'name'=>'Tom'),		array('id'=>2,'name'=>'Lily'),		array('id'=>1,'name'=>'Smith'),	);	echo "<select name='menu2'>";	foreach($arrMenu as $item2){		echo "<option value='{$item2['id']}'";		if($item2['id']==$_GET['id'])			echo "selected";		echo " >{$item2['name']}</option>";	}	echo "</select>";}?>
Copy after login

<html> <head>  <title>测试Variable Modifiers</title> </head> <body><form name="frm"><select name="s1" onChange="record(this.value)"> <option selected>请选择</option> <option value="1">天文</option> <option value="2">地理</option> <option value="3">算术</option></select><div id="show"></div></form><script language='javascript'>//Ajaxvar xmlHttp;	function createXMLHttpRequest() {		if(window.XMLHttpRequest) {			xmlHttp = new XMLHttpRequest();		} else if (window.ActiveXObject) {			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");		}	}	function record(id){		createXMLHttpRequest();		url = "Ajax_select.php?id="+id+"&ran="+Math.random();		method = "GET";		xmlHttp.open(method,url,true);		xmlHttp.onreadystatechange = show;		xmlHttp.send(null);	}	function show(){		if (xmlHttp.readyState == 4){			if (xmlHttp.status == 200){				var text = xmlHttp.responseText;				document.getElementById("show").innerHTML = text;			}else {				alert("response error code:"+xmlHttp.status);			}		}	}</script> </body></html>
Copy after login

你可以使用$_GET,或者$_getJson来处理,方便

这个能测试,至于能懂多少就看你的了,先会用,再慢慢琢磨
PHP code

/* Created on [2012-7-4] Author[Newton] */
#Ajax_select.php 此php和html要分为两个页面
if(isset($_GET['id'])){
    #$arrMenu数组可以是数据库查询的结果数组等任意二维数组
    $arrMenu=arr……


onChange="record(this.value)" 取不到value值。。

会报一个警告,オブジェクトを指定してください。
我以为是参数传错了,后来发现把参数去掉也报这个错

谢谢各位,搞定了

会报一个警告,オブジェクトを指定してください。
我以为是参数传错了,后来发现把参数去掉也报这个错


出这个问题是什么情况?怎么解决啊,楼主
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Zhengtu IPx classic animation 'Journey to the West' The journey to the west is fearless and fearless Jun 10, 2024 pm 06:15 PM

Journey through the vastness and set foot on the journey to the west! Today, Zhengtu IP officially announced that it will launch a cross-border cooperation with CCTV animation "Journey to the West" to jointly create a cultural feast that combines tradition and innovation! This cooperation not only marks the in-depth cooperation between the two major domestic classic brands, but also demonstrates the unremitting efforts and persistence of the Zhengtu series on the road of promoting Chinese traditional culture. Since its birth, the Zhengtu series has been loved by players for its profound cultural heritage and diversified gameplay. In terms of cultural inheritance, the Zhengtu series has always maintained respect and love for traditional Chinese culture, and skillfully integrated traditional cultural elements into the game, bringing more fun and inspiration to players. The CCTV animation "Journey to the West" is a classic that has accompanied the growth of generations.

Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Double chef ecstasy! 'Onmyoji' x 'Hatsune Miku' collaboration starts on March 6 Feb 22, 2024 pm 06:52 PM

NetEase's "Onmyoji" mobile game announced today that the Onmyoji x Hatsune Miku limited collaboration will officially begin on March 6. The collaboration-limited SSR Hatsune Miku (CV: Saki Fujita) and SSR Kagamine Rin (CV: Asami Shimoda) are coming to Heian Kyo! The linkage online special performance event will officially start in the game on March 9~

Classic reunion, reversal of time and space, 'Dragon 2' x 'Westward Journey' movie linkage decision Classic reunion, reversal of time and space, 'Dragon 2' x 'Westward Journey' movie linkage decision Mar 28, 2024 pm 04:40 PM

Classic reunion, reversing time and space. The "Dragon 2" mobile game and the classic movie "Westward Journey" are jointly scheduled to be released on April 11! It coincides with the anniversary celebration of the "Dragon 2" mobile game. We invite everyone to relive the classic memories and once again witness the battle between Zhizunbao and Zixia until death. The legendary story of Chongqing. There must be colorful auspicious clouds, and there must be golden armor and holy clothes. When the phrase "Prajna Paramita" echoes in your ears, will you think of the tear that Zixia left in the heart of the Supreme Treasure? A glance for ten thousand years, but it is impossible to escape the fate of fate. Even if there is no return, my love will never change until death. The Westward Journey collaboration appearance [One Eye for Ten Thousand Years] and [God's Will] will be launched simultaneously with the anniversary version. I hope you can wear the golden armor or meet your own unparalleled hero, and return to your most passionate youth. Five hundred years of protection, true love till death, said by chance when I met Luoyang that day

Fried chicken is a great business and there is no room for error! 'Backwater Cold' links up with KFC, causing players to 'dance upon hearing the chicken' Fried chicken is a great business and there is no room for error! 'Backwater Cold' links up with KFC, causing players to 'dance upon hearing the chicken' Apr 17, 2024 pm 06:34 PM

On the date, "Backwater Cold" officially announced that it will launch a linkage with KFC from April 19th to May 12th. However, the specific content of the linkage has left many people stunned. They repeatedly said, "It's embarrassing to heaven" and "It's important to society." died"! The reason lies in the slogan of this theme event. Friends who have seen the KFC linkage of "Genshin Impact" and "Beng Tie" must have the impression that "encountering another world and enjoying delicious food" has become a reality in "Ni Shui Han" Now: shout out to the clerk, "God is investigating the case, who are you?" The clerk needs to reply, "Fried chicken is a big business, and there is no room for error!" Training guide for employees: Never laugh! Not only that, this collaboration also held a dance competition. If you go to the theme store and perform the "Dance when you hear 'Ji'" dance move, you can also get a small rocking music stand. Embarrassing, so embarrassing! But that's what I want

Linkage and dependency functions of Java development form fields Linkage and dependency functions of Java development form fields Aug 07, 2023 am 08:41 AM

Introduction to the linkage and dependency functions of Java development form fields: In Web development, forms are a frequently used interaction method. Users can fill in information and submit it through the form, but cumbersome and redundant form field selection operations often cause problems for users. bring inconvenience. Therefore, the linkage and dependency functions of form fields are widely used to improve user experience and operational efficiency. This article will introduce how to use Java development to implement linkage and dependency functions of form fields, and provide corresponding code examples. 1. Implementation form of form field linkage function

The collaboration between 'Diablo: Immortal' and 'Legend of Sword and Fairy' has been decided! The collaboration between 'Diablo: Immortal' and 'Legend of Sword and Fairy' has been decided! Apr 17, 2024 pm 02:58 PM

NetEase Games announced today that "Diablo: Immortal" has decided to link up with "Legend of Sword and Fairy". On April 24th, "One Sword is Happy" opens a new era of immortal cultivation! One is a classic of Western fantasy, and the other is the eternal memory of Eastern immortals. The dark universe and the fairy sword are intertwined in time and space, and the two major IPs work together to slay demons. On April 24th, the immortal legend of justice and chivalry will be staged in Sanctuary!

Yuanmeng Star Ultraman genuine linkage: Zero Zeta resonates with the power of Ultra, bursting out with sparks of passion! Yuanmeng Star Ultraman genuine linkage: Zero Zeta resonates with the power of Ultra, bursting out with sparks of passion! Feb 24, 2024 pm 02:25 PM

Yuanmeng Star Ultraman genuine linkage series, Zero Zeta's same fashion details are revealed today. I believe everyone has been looking forward to it for a long time. The co-branded fashion with Zero Zeta has been launched today. Follow the editor to take a look at this I hope it can help you with more details about the Ultraman link-up. Yuanmeng Star Ultraman genuine linkage: Zero Zeta resonates with the power of Ultra, bursting out with sparks of passion! As a new generation of young Ultra Warriors in the Kingdom of Light, Ultraman Zero is the captain of the Ultimate Zero Guard. Ultraman Zero is uninhibited, kind, passionate and unrestrained. "Aren't you still at ease with me by your side? Zero will do his best to protect you." Star treasures, star treasures, put on Ultraman Zero's costumes and fight bravely with Zero! Detailed display, modeling action, appearance action, standby action, Zeta, I am not a one-third dabbler, I am the universe

How to combine ECharts and php interface to realize multi-chart linkage statistical chart display How to combine ECharts and php interface to realize multi-chart linkage statistical chart display Dec 18, 2023 am 10:07 AM

In the field of data visualization, ECharts is a widely used front-end chart library, and its powerful data visualization functions are sought after by various industries. In actual projects, we often encounter situations where multiple charts need to be displayed in a linked manner. This article will introduce how to combine ECharts and PHP interfaces to realize the linked statistical chart display of multiple charts, and give specific code examples. 1. Pre-requisite skills In the practice of this article, you need to master the following skills: basic knowledge of HTML, CSS, and JavaScript;

See all articles