首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTA: Javascript计算器-添加新变量

HTA: Javascript计算器-添加新变量
EN

Stack Overflow用户
提问于 2017-05-14 16:10:27
回答 1查看 111关注 0票数 0

我是一名神经外科医生,试图更新我四年前发明的javascript计算器。它采取了许多变量的颅内动脉瘤,并根据三个不同的队列研究给出了估计破裂率。我试图用同样的方法包含一个新的元分析,其中包含更多的变量。不幸的是,当我添加新变量和if函数时,计算器会中断.

最初的计算器工作方式如下:http://www.timkilleen.com/calc1.html

代码语言:javascript
复制
<strong><large>Aneurysm Calculator - ISUIA</large></strong>
<br>
<br>

<script type="text/javascript">
    function getRisk()
    {
        var size = window.document.getElementById('An_Size').value;
        var location = window.document.getElementById('locate').value;
        var ysah = window.document.getElementById('yessah');
        var nsah = window.document.getElementById('nosah');

        x=size;
        y=location;
            z=ysah.checked?"yes":"no";

   if( x==0         ) output(" -- / --")
               if( x>0&& x<7        && y=="ant" && z=="no"  ) output(" 1 /0 ")
if( x>=7&& x<12     && y=="ant" && z=="no"  ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25     && y=="ant" && z=="no"  ) output(" 0.971 /14.5 ")
if( x>=25   && y=="ant" && z=="no"  ) output(" 0.92 /40 ")
if( x>0&& x<7       && y=="post"    && z=="no"  ) output(" 0.995 /2.5 ")
if( x>=7&& x<12     && y=="post"    && z=="no"  ) output(" 0.971 /14.5 ")
if( x>=12&&x<25     && y=="post"    && z=="no"  ) output(" 0.9632 /18.4 ")
if( x>=25   && y=="post"    && z=="no"  ) output(" 0.9 /50 ")
if( x>0&& x<7       && y=="int"     && z=="no"  ) output(" 1 /0 ")
if( x>=7&& x<12     && y=="int"     && z=="no"  ) output(" 1 /0 ")
if( x>=12&&x<25     && y=="int"     && z=="no"  ) output(" 0.994 /3 ")
if( x>=25   && y=="int"     && z=="no"  ) output(" 0.9872 /6.4 ")
if( x>0&& x<7       && y=="ant" && z=="yes"     ) output(" 0.997 /1.5 ")
if( x>=7&& x<12     && y=="ant" && z=="yes" ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25     && y=="ant" && z=="yes"     ) output(" 0.971 /14.5 ")
if( x>=25   && y=="ant" && z=="yes"     ) output(" 0.92 /40 ")
if( x>0&& x<7       && y=="post"    && z=="yes"     ) output(" 0.9932 /3.4 ")
if( x>=7&& x<12     && y=="post"    && z=="yes"     ) output(" 0.971 /14.5 ")
if( x>=12&&x<25     && y=="post"    && z=="yes"     ) output(" 0.9632 /18.4 ")
if( x>=25   && y=="post"    && z=="yes"     ) output(" 0.9 /50")
if( x>0&& x<7       && y=="int"     && z=="yes"     ) output(" 1 /0 ")
if( x>7&& x<12      && y=="int"     && z=="yes"     ) output(" 1 /0 ")
if( x>=12&&x<25     && y=="int"     && z=="yes"     ) output(" 0.994 /3 ")
if( x>=25   && y=="int"     && z=="yes"     ) output(" 0.9872 /6.4 ")

    }

    function output(str)
    {
        var arr = str.split("/");
        var one_yr_risk = parseFloat(arr[0]);
        var life_expectancy = parseFloat(window.document.getElementById('life_expectancy').value);
        var cum_risk="--";
        var five_yr_risk="--"
        {
            five_yr_risk = arr[1];
            cum_risk = Math.round(((1-Math.pow((one_yr_risk), life_expectancy))*100)*10)/10;
        }
        window.document.getElementById('r2').value=five_yr_risk;    
        if(life_expectancy<10)
            cum_risk="--";

        if(cum_risk===0)
            cum_risk="0*";

        window.document.getElementById('r1').value=cum_risk;
    }

</script>

<img alt="" src="/sites/default/files/COW.gif" style="width: 250px; height: 284px; border-width: 0px; border-style: solid; margin: 0px;" />
<form action="" id="riskform" onSubmit="return false;">
   <fieldset>
    <label for="locate">Location</label>
    <select id="locate" name='locate'
    onchange="getRisk()">
    <option value="ant">Anterior circulation</option>
    <option value="post">Posterior circulation (incl. PCom)</option>
    <option value="int">Intracavernous</option>

   </select>
   <br>
<br>
    <p>
    <label class="inlinelabel" for='includeinscription'>
    Size(mm)</label>
    <input type="text"  id="An_Size" size=7 onKeyUp="getRisk()"
    name="size" value="0"  />
    </p>
    <label >Previous SAH?</label>
    <input type="radio"  name="prevsah" value="yessah" id="yessah"
    onclick="getRisk()" />
    Yes
    <input type="radio"  name="prevsah" value="nosah" id="nosah"
    onclick="getRisk()" />
    No
<br>
<br>    
<label for="Five_Year">5 Year Rupture Risk (%)</label>
<input type="text" name="val3" id="r2"><span id="result2"></span>
          <p>
<p>
<br>
    <label class="inlinelabel" for='includeinscription'>
    Estimated life expectancy (minimum 10 years)</label>
    <input type="text"  id="life_expectancy" size=7 onKeyUp="getRisk()"
    name="size" value="0"  />
    </p>

<label for="One_Year">Cumulative Lifetime Rupture Risk (%)</label>
<input type="text" name="val3" id="r1"><span id="result1"></span>

    <div id="Final_Risk"></div>

    </fieldset>
</form>

我增加了两个新的是/否变量和一个额外的下拉选择(种族),这成倍地增加了可能的if函数的大小(不包括为了简洁起见,例如下面)。

代码语言:javascript
复制
if( x>=20           && y=="oth" && z=="no" && u=="yes" && v=="no" && w="jp"     ) output(" 0.9644 /17.8 ")

新变量设置如下:

代码语言:javascript
复制
<script type="text/javascript">
    function getRisk()
    {
        var size = window.document.getElementById('An_Size').value;
        var location = window.document.getElementById('locate').value;
        var ysah = window.document.getElementById('yessah');
        var nsah = window.document.getElementById('nosah');
        var eth = window.document.getElementById('ethno').value;
        var osev = window.document.getElementById('oversev');
        var usev = window.document.getElementById('undersev');
        var yhtn = window.document.getElementById('yhyp');
        var nhtn = window.document.getElementById('nhyp');


        u=yhtn.checked?"yes":"no";
        v=osev.checked?"yes":"no";
        w=eth;
        x=size;
        y=location;
        z=ysah.checked?"yes":"no";

我非常肯定,我在这里错误地实现了附加变量和/或错误地设置了html表单:

代码语言:javascript
复制
   </select>
    </p>
    <label >Previous SAH?</label>
    <input type="radio"  name="prevsah" value="yessah" id="yessah"
    onclick="getRisk()" />
    Yes
    <input type="radio"  name="prevsah" value="nosah" id="nosah"
    onclick="getRisk()" />
    No
    <p>
    <label >Hypertension?</label>
    <input type="radio"  name="htn" value="yhyp" id="yhyp"
    onclick="getRisk()" />
    Yes
    <input type="radio"  name="htn" value="nhyp" id="nhyp"
    onclick="getRisk()" />
    No
    <p>
    <label >Age over 70?</label>
    <input type="radio"  name="oversev" value="osev" id="osev"
    onclick="getRisk()" />
    Yes
    <input type="radio"  name="oversev" value="usev" id="usev"
    onclick="getRisk()" />
    No
<br>

如有任何建议,将不胜感激。

谨致问候,

时间

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-14 16:52:36

检查了你的破译代码。它在控制台上出错了。Uncaught ReferenceError: Invalid left-hand side in assignment。尝试对所有条件使用w=="jp"而不是w="jp"

并替换以下内容

代码语言:javascript
复制
var osev = window.document.getElementById('oversev');
var usev = window.document.getElementById('undersev');

使用

代码语言:javascript
复制
var osev = window.document.getElementById('osev');
var usev = window.document.getElementById('usev');

你用错了身份证。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43966112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档