posts - 297,  comments - 1618,  trackbacks - 0
          測試時,發現了代碼中js出現的一個bug。
          var?shouldAttendPersons?=?;
          var?camePersons?=?;
          if(camePersons??>?shouldAttendPersons?)?{
          ???????alert(
          "");
          }


          當shouldAttendPersons為8,camePersons為10時,打出了提示信息,原來js在這種情況下是將shouldAttendPersons和camePersons當成字符串比較的。

          ?????? 解決方法暫時找到兩種:
          ?????1)

          var?shouldAttendPersons?=?;
          var?camePersons?=?;
          if(parseInt(camePersons)??>?parseInt(shouldAttendPersons)?)?{
          ???????alert(
          "");
          }

          ???? 2)

          var?shouldAttendPersons?=?;
          var?camePersons?=?;
          if(1*camePersons??>?1*shouldAttendPersons?)?{
          ???????alert(
          "");
          }

          ????? 俺真是js菜鳥。
          posted on 2007-02-11 23:47 阿蜜果 閱讀(3742) 評論(1)  編輯  收藏 所屬分類: Javascript


          FeedBack:
          # re: js數字比較
          2008-03-31 12:38 | fantasybei
          當shouldAttendPersons為8,camePersons為10時,打出了提示信息,原來js在這種情況下是將shouldAttendPersons和camePersons當成字符串比較的。

          ????shouldAttendPersons為8,camePersons為10時,當成數字的時候也應該alert吧?怎么能根據這個說明 “js在這種情況下是將shouldAttendPersons和camePersons當成字符串比較的”呢?  回復  更多評論
            
          <2007年2月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728123
          45678910

                生活將我們磨圓,是為了讓我們滾得更遠——“圓”來如此。
                我的作品:
                玩轉Axure RP  (2015年12月出版)
                

                Power Designer系統分析與建模實戰  (2015年7月出版)
                
               Struts2+Hibernate3+Spring2   (2010年5月出版)
               

          留言簿(263)

          隨筆分類

          隨筆檔案

          文章分類

          相冊

          關注blog

          積分與排名

          • 積分 - 2298181
          • 排名 - 3

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 白玉县| 新巴尔虎右旗| 都兰县| 盖州市| 济南市| 报价| 六枝特区| 长沙县| 洪江市| 藁城市| 江西省| 鲁山县| 泸溪县| 确山县| 新泰市| 汨罗市| 涟源市| 丰都县| 郴州市| 大同县| 双江| 荣昌县| 日照市| 交城县| 越西县| 黄浦区| 绵阳市| 永安市| 乐亭县| 偃师市| 容城县| 宁化县| 江油市| 丰台区| 阿拉善右旗| 潜江市| 册亨县| 会宁县| 深水埗区| 芜湖县| 哈尔滨市|