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

根据下拉菜单选中值显示内容
为什么第一次选择下拉菜单 ExpressNumber元素的值会改变,第二次就不会变了?
<!DOCTYPE HTML>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>无标题文档</title>
  <script src="../../js/jquery-1.8.3.min.js" type="text/javascript" ></script>
  <script type="text/javascript">
 //<![CDATA[
  $(function(){
    $("#DropExpress").change(function(){
        var expressValue=$(this).val();
        if( expressValue == '9999' ){
           $("#ExpressNumber").replaceWith("请输入快递公司和快递单号"); 
        }
else if( expressValue == '8888' ){
           $("#ExpressNumber").replaceWith("物流公司电话"); 
        }
else{
$("#ExpressNumber").replaceWith("快递单号"); 
}
    });
});
  //]]>
  </script>
  </head>

  <body>
<select name="DropExpress" id="DropExpress">
    <option value="">请选择</option>
    <option value="97">中通快递</option>
    <option value="9999">其他快递</option>
    <option value="8888">物流公司</option>
  </select>
<br >
<span id="ExpressNumber">快递单号</span>
</body>
</html>

------解决方案--------------------
replaceWith你之际把$("#ExpressNumber")替换成了你的文本,第二次压根找不到$("#ExpressNumber")这个元素了

replaceWith改成$("#ExpressNumber").html('.....')