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

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 青阳县| 铁力市| 玉龙| 北海市| 米林县| 嘉善县| 金阳县| 延吉市| 保靖县| 彰化县| 旅游| 瓦房店市| 大悟县| 蒙阴县| 贡觉县| 六盘水市| 本溪市| 苗栗市| 榆中县| 连州市| 井冈山市| 新巴尔虎右旗| 长顺县| 通州市| 斗六市| 南乐县| 交口县| 山丹县| 彭泽县| 旬邑县| 锡林浩特市| 麻栗坡县| 寿光市| 青海省| 舒城县| 米易县| 吉木萨尔县| 平安县| 馆陶县| 满洲里市| 信丰县|