注 : 该代码和 jQuery有冲突.. 需要使用jQuery的朋友慎用~~
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/submit.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/tbra-aio.js"></script> <script type="text/javascript" src="js/districtselector.js"></script> <style type="text/css" charset="utf-8"> #district select { width: 88px; } </style> <label for="district">所在地区</label> <span id="district"> <select name="province" title="省" id="province">\</select> <select name="city" title="市" id="city"></select> <select name="area" title="区" id="area"></select> </span> <button onclick="goDistrict();">确定</button> <script type="text/javascript"> var Y = YAHOO.util; var provSel = Y.Dom.get('province'); var citySel = Y.Dom.get('city'); var distSel = Y.Dom.get('area'); var cv = TB.form.DistrictSelector.attach(provSel, citySel, distSel); window['distSelector'] = cv; function goDistrict(){ // 由于淘宝 js直接获取的 是 地区的代码.. 所以在这里必须通过这种方式获取真正的地区 var province = Y.Dom.get('province').options[Y.Dom.get('province').selectedIndex].text; var city = Y.Dom.get('city').options[Y.Dom.get('city').selectedIndex].text; var area = Y.Dom.get('area').options[Y.Dom.get('area').selectedIndex].text; alert(province + city + area); } </script> </body> </html>