You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改getDilation()函数适配数字输入框计算Bishop评分?

修改getDilation()适配数字输入框

没问题,咱们把原来针对单选按钮的函数改成适配数字输入框的版本,核心思路是直接读取输入的数值,然后根据Bishop评分的规则映射对应的分数。

第一步:明确Bishop评分中宫颈扩张的分数规则

先确认常规的Bishop评分映射逻辑(如果你的规则不同,直接调整区间即可):

  • 0cm → 0分
  • 1-2cm → 1分
  • 3-4cm → 2分
  • 5-6cm → 3分
  • 7-10cm → 4分

第二步:修改getDilation()函数

替换原来的函数代码为下面的版本,逻辑简洁直接:

// getDilation() 根据输入的宫颈扩张数值计算对应的Bishop评分分数
function getDilation() {
  // 获取数字输入框的数值,转换为Number类型(避免字符串比较问题)
  const dilationValue = Number(document.getElementById('selecteddilation').value);
  
  // 初始化分数为0
  let dilationPoints = 0;
  
  // 根据数值区间匹配对应的分数(从高到低判断,避免区间重叠)
  if (dilationValue >= 7 && dilationValue <= 10) {
    dilationPoints = 4;
  } else if (dilationValue >= 5 && dilationValue < 7) {
    dilationPoints = 3;
  } else if (dilationValue >= 3 && dilationValue < 5) {
    dilationPoints = 2;
  } else if (dilationValue >= 1 && dilationValue < 3) {
    dilationPoints = 1;
  } else if (dilationValue === 0) {
    dilationPoints = 0;
  }
  
  // 兜底处理:如果输入超出0-10范围(前端限制可被绕过,做个保险)
  if (dilationValue < 0 || dilationValue > 10) {
    dilationPoints = 0; // 也可以根据需求提示错误,这里默认设为0
  }
  
  return dilationPoints;
}

代码说明

  • 用Number()把输入框的字符串值转成数字,避免后续区间判断时出现字符串比较的错误;
  • 从高到低判断数值区间,逻辑更清晰,不会出现区间重叠的问题;
  • 增加了兜底判断,防止输入超出0-10的范围(虽然你的输入框设置了min和max,但前端限制可以被绕过,做个保险更稳妥)。

如果你的Bishop评分规则和上面的区间不同,只需要调整if-else里的数值范围和对应的分数即可。

内容的提问来源于stack exchange,提问作者molecoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:33:08