未加星標 ajax三級聯動的實現方法

來源:互聯網
上載者:User

標籤:san   省份   3.1.1   遍曆數組   3.1   三級聯動   ajax   下拉   src   

<div id="sanji"></div>
 

下面考慮的是要有省市區這三列,這三列用的是下拉式清單,那麼裡面要用<option></option> 因為是用js和jquery來寫,那麼首先要考慮的就是要引入jquery包和js檔案,然後把寫三個下拉式清單

<script src="jquery-3.1.1.min.js"></script>
<script src="sanji.js"></script>

$(document).ready(function(e){
var str="<select id=‘sheng‘></select><select id=‘shi‘></select><select id=‘qu‘></select>"; //先寫三個下拉式清單放到div裡面
$("#sanji").html(str);
fullsheng();
fullshi();
fullqu();
$("#sheng").change(function(){
fullshi();
fullqu();
})
$("#shi").change(function(){
fullqu();
})
//載入省份資訊
function fullsheng()
{
var pcode="0001";//根據父級代號查資料
$.ajax({
async:false, //採用非同步方式
url:"sanjichuli.php",
data:{pcode:pcode},
type:"POST",
dataType:"JSON",
success:function(data){
//這裡傳過來的data是個數組
str="";
for(var j in data)//js中的遍曆數組用for來表示
{
str +="<option value=‘"+data[j].AreaCode+"‘>"+data[j].AreaName+"</option>";
}
$("#sheng").html(str);
}
})
}
//載入市的資訊
function fullshi()
{
var pcode=$("#sheng").val();
$.ajax({
async:false,
url:"sanjichuli.php",
data:{pcode:pcode},
type:"POST",
dataType:"JSON",
success:function(data){
//這裡傳過來的data是個數組
str="";
for(var j in data)//js中的遍曆數組用for來表示
{
str +="<option value=‘"+data[j].AreaCode+"‘>"+data[j].AreaName+"</option>";
}
$("#shi").html(str);
}
})
}
// 載入區的資訊
function fullqu()
{
var pcode=$("#shi").val();
$.ajax({
url:"sanjichuli.php",
data:{pcode:pcode},
type:"POST",
dataType:"JSON",
success:function(data){
//這裡傳過來的data是個數組
str="";
for(var j in data)//js中的遍曆數組用for來表示
{
str +="<option value=‘"+data[j].AreaCode+"‘>"+data[j].AreaName+"</option>";
}
$("#qu").html(str);
}
})
}
})

未加星標 ajax三級聯動的實現方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.