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

          積分與排名

          • 積分 - 2298155
          • 排名 - 3

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 达尔| 甘孜| 乌海市| 夹江县| 合肥市| 贺州市| 阿克| 承德市| 新巴尔虎左旗| 瑞安市| 荣成市| 高台县| 沙河市| 兴安盟| 临夏县| 荔波县| 鄱阳县| 电白县| 延寿县| 鄂托克旗| 甘德县| 东乡县| 辛集市| 株洲县| 井冈山市| 板桥市| 霍山县| 晋江市| 巴楚县| 抚松县| 小金县| 潮安县| 遂溪县| 赞皇县| 乐昌市| 尉犁县| 盘锦市| 泗阳县| 新民市| 沛县| 乌兰察布市|