本帖最后由 bang1992 于 2011-08-10 09:53:03 编辑

解决方案 »

  1.   

    trim这个是不兼容的,请换掉了
      

  2.   

    如果你想要去掉空格你可以s = s.replace(/(^\s*)|(\s*$)/g, "");
      

  3.   

    没问题啊<script>
    function sum(id1, id2, idSum) {
    var text1 = document.getElementById(id1).value;
    var text2 = document.getElementById(id2).value; if(text1 == null || text1 == '') {
    document.getElementById(id1).value = '0';
    text1 = '0';
    } if(text2 == null || text2 == '') {
    document.getElementById(id2).value = '0';
    text2 = '0';
    } if(text1 != null && text1 != '' && isNaN(text1) == false && text2 != null && text2 != '' && isNaN(text2) == false) {
    document.getElementById(idSum).value = parseInt(text1, 10) + parseInt(text2, 10);
    } else {
    if(text1 != null && text1 != '' && isNaN(text1) == false) {
    document.getElementById(idSum).value = text1;
    } else if(text2 != null && text2 != '' && isNaN(text2) == false) {
    document.getElementById(idSum).value = text2;
    } else {
    document.getElementById(idSum).value = '0';
    }
    }
    }
    </script>
    <input type="text" id="num1">
    <input type="text" id="num2">
    <input type="text" id="sumShow">
    <input type="button" value="sum" onclick="sum('num1', 'num2', 'sumShow')">
      

  4.   

    <input type="text" id="crs_hub_hotel" name="crsHubHotel" onkeyup="sum('crs_hub_hotel', 'crs_hub_roomtype', 'crs_hub_total');">大侠请问我要把这个只能输入正整数,不能小数点,怎么在这里面写啊
      

  5.   

    <input type="text" id="crs_hub_hotel" name="crsHubHotel"onkeyup="check(this);sum('crs_hub_hotel', 'crs_hub_roomtype', 'crs_hub_total');">function check(obj){
    if(!/^(?!0\d+)\d*$/.test(obj.value)){
    obj.value = "";
    }
    }