三級聯動 修改部分

頁面js部分


<script type="text/javascript">

    $(document).ready(function() {
     function getObjectFromStr(str) {
return (typeof(str) == "object") ? str : eval('(' + str + ')');
}
$("#commentForm").validate();
var provinceURL = "select_province.action";
function changeProvince(countryName) {
$.post(provinceURL,{'country':countryName},function(result) {
  var object = getObjectFromStr(result);
  var getprovince=$('#beprovince').val();
  $('#selprovince').find('option:gt(0)').remove();
  for(var i=0,n=object.length;i<n;i++) {
  var element = object[i];
  if(element==getprovince)
  {
  $('#selprovince').append('<option value="' + element + '" selected="selected">' + element + '</option>');
  }
  else
  {
  $('#selprovince').append('<option value="' + element + '">' + element + '</option>');
  }  
  }
 });
}
$('#selcountry').change(function() {
 var pars = $(this).val();
 changeProvince(pars);
});
changeProvince($('#selcountry').val());


function getObjectFromStr(str) {
return (typeof(str) == "object") ? str : eval('(' + str + ')');
}
$("#commentForm").validate();
var cityURL = "select_city.action";
function changeCity(provinceName) {
 $.post(cityURL,{'province':provinceName},function(result) {
  var object = getObjectFromStr(result);
  var getcity=$('#becity').val();
  $('#selcity').find('option:gt(0)').remove();  
  for(var i=0,n=object.length;i<n;i++) {
  var element = object[i];
  if(element==getcity)
  {
  $('#selcity').append('<option value="' + element + '" selected="selected">' + element + '</option>');
  }
  else
  {
  $('#selcity').append('<option value="' + element + '">' + element + '</option>');
  }
     
  }
 });
}


 



$('#selprovince').change(function() {
var pars = $(this).val();
changeCity(pars);
});
changeCity($('#beprovince').val());

    });

  </script>



頁面部分:

 
    <tr>
    <td width="20%" align="right">國家:</td>
    <td width="50%">
      <s:select id="selcountry" theme="simple"  name="readers.country" list="listcop" listKey="NAME"  listValue="NAME"  headerKey="0"  disabled="true"/>  
 </td>
    <td width="2%" align="center">&nbsp;</td>
    <td width="28%">&nbsp;</td>
  </tr>
  <tr>
    <td width="20%" align="right">省:</td>
    <td width="50%">
             <select id="selprovince" name="readers.province"  disabled="true">
               <option value=""> ---請選擇---</option>
               <s:iterator value="listprovince" status="index">   
                   <option value="<s:property value="NAME"/>">   <s:property value="NAME"/>  </option>
                               </s:iterator> 
        </select>
 </td>
    <td width="2%" align="center">&nbsp;</td>
    <td width="28%">&nbsp;</td>
  </tr>
  <tr>
    <td width="20%" align="right">城市:</td>
    <td width="50%">
          <select id="selcity" name="readers.city"  disabled="true">
            <option value=""> ---請選擇---</option>
            <s:iterator value="listcity" status="index">   
                <option value="<s:property value="NAME"/>">   <s:property value="NAME"/>  </option>
                              </s:iterator> 
        </select>
</td>

發佈了41 篇原創文章 · 獲贊 5 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章