日期:2014-05-16  浏览次数:20293 次

JQuey无法给对象赋值
CSS code

   #city_selected{ width:200px; height:100px; position:absolute; display:none;}


HTML code

<script type="text/javascript">
$("#change_city").click(function(){
    tipsWindown("切换城市", "text:"+function(){var txt = $("#city_selected").html(); return txt;}(), "250", "150", "true", "", "true", "id");
    // var num = $("#city_selected select");
    // alert(num);
    });
</script>

  <div id="city_selected">
   <table border="0" class="no_border">
      <tr>
        <td><select onchange="selectCity(this)"><option selected="selected">选择省份</option><option>江苏</option></select></td>
        <td><select onchange="selectCity(this)"><option selected="selected">选择市</option><option>苏州</option></select></select></td>
        <td><select onchange="selectCity(this)"><option selected="selected">选择市区</option><option>园区</option></select></select></td>
      </tr>
      <tr>
      </tr>
   </table>
   <div id="selected_city_result"></div>
    <script type="text/javascript">
          function selectCity(e){
               //alert($("#selected_city_result").html());
               $("#selected_city_result").html(e.value);
              }
    </script>
</div>


// $("#selected_city_result").html(e.value); 这句老是不起作用,求详解!
// Thanks.

------解决方案--------------------
你先alert(e.value)看看出来什么值
------解决方案--------------------
<td><select onchange="selectCity(this)"><option selected="selected" value="sheng">选择省份</option><option value="jiangsu">江苏</option></select></td>
<td><select onchange="selectCity(this)"><option selected="selected" value="city">选择市</option><option value="suzhou">苏州</option></select></select></td>
<td><select onchange="selectCity(this)"><option selected="selected" value="shiqu">选择市区</option><option value="yuanqu">园区</option></select></select></td>

没有给Select的Option项赋值
------解决方案--------------------
因为你没有值,所以肯定层里面不会显示什么了 你加上试试看
------解决方案--------------------
用append看下
------解决方案--------------------
e你传过来的是DOM对象
他不会自动转化为jquery对象
------解决方案--------------------
用document.getElementById("selected_city_result").innerHTML=e.value;
或者 先把e转化为jquery对象
------解决方案--------------------
JScript code

          function selectCity(e){
               $("#selected_city_result").html($(e).val());
              }

------解决方案--------------------
刚说错了 
你value根本就没值