dscojuxf69080 2016-09-17 07:35
浏览 16
已采纳

如何输入除了0.0到5.0之外

I am new in javascript and don't know what to in this case please provide me solution

<input type="text" name="technical" maxlength="3" id="numa" onKeyUp="this.value = minmax(this.value, 0, 5)" class="input-text persent managementskill" value="<?=set_value('technical',$this->input->post('technical'))?>" />

<script type="text/javascript">
function minmax(value, min, max) 
{

    if(parseInt(value) < min || isNaN(value)) 
        return 0; 
    else if(parseInt(value) > max) 
        return 5; 
    else return value;

}
</script>

This is my code is working fine for the first entry of input it will not except after 5 but I want if we enter 5.1 then it automatically converts that num to 5.0 want this to except only 0.0 to 5.0 what to do in my function please help

  • 写回答

3条回答 默认 最新

  • douce1368 2016-09-17 07:42
    关注

    in simple way you can just return '5.0'; just try it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)