- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的第一个脚本终于在 drupal 站点上作为 block 独立工作。问题是,我需要它们在同一页面上并排工作。当我尝试这个时,只有其中一个有效。已四处搜寻以尝试找到解决方案 - 所有变量和元素都是唯一的,但似乎仍然存在冲突。代码如下:
block 1 代码:
<script type="text/javascript">
(function(){
"use strict";
window.getRisk = function()
{
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 x=size;
var y=location;
var 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>
block 2 代码:
<script type="text/javascript">
(function(){
"use strict";
window.getRiskJp = function()
{
var sizejp = window.document.getElementById('An_Size_Jp').value;
var locationjp = window.document.getElementById('location_Jp').value;
var a=sizejp;
var b=locationjp;
if( a<3 ) output(" -- / --")
if( a>=3&& a<5 && b=="mca" ) output(" 0.9977 /0.23 ")
if( a>=5&& a<7 && b=="mca" ) output(" 0.9969 /0.31 ")
if( a>=7&& a<10 && b=="mca" ) output(" 0.9844 /1.56")
if( a>=10&& a<25 && b=="mca" ) output(" 0.9589 /4.11 ")
if( a>=25&& b=="mca" ) output(" 0.8313 /16.87")
if( a>=3&& a<5 && b=="aca" ) output(" 0.991 /0.90 ")
if( a>=5&& a<7 && b=="aca" ) output(" 0.9925 /0.75 ")
if( a>=7&& a<10 && b=="aca" ) output(" 0.9803 /1.97")
if( a>=10&& a<25 && b=="aca" ) output(" 0.9476 /5.24 ")
if( a>=25&& b=="aca" ) output(" 0.6023 /39.77")
if( a>=3&& a<5 && b=="ica" ) output(" 0.9986 /0.14 ")
if( a>=5&& a<7 && b=="ica" ) output(" 1 /0 ")
if( a>=7&&a<10 && b=="ica" ) output(" 0.9881 /1.19")
if( a>=10&&a<25 && b=="ica" ) output(" 0.9893 /1.07 ")
if( a>=25&& b=="ica" ) output(" 0.8939 /10.61")
if( a>=3&& a<5 && b=="icapcomm" ) output(" 0.9986 /0.41 ")
if( a>=5&& a<7 && b=="icapcomm" ) output(" 1 /1 ")
if( a>=7&&a<10 && b=="icapcomm" ) output(" 0.9881 /3.19")
if( a>=10&&a<25 && b=="icapcomm" ) output(" 0.9893 /6.12 ")
if( a>=25&& b=="icapcomm" ) output(" 0 / around 100")
if( a>=3&& a<5 && b=="bassca" ) output(" 0.9977 /0.23 ")
if( a>=5&& a<7 && b=="bassca" ) output(" 0.9954 /0.46 ")
if( a>=7&& a<10 && b=="bassca" ) output(" 0.9903 /0.97 ")
if( a>=10&& a<25 && b=="bassca" ) output(" 0.9306 /6.94 ")
if( a>=25&& b=="bassca" ) output(" 0 /around 100")
if( a>=3&& a<5 && b=="vert" ) output(" 1 /0 ")
if( a>=5&& a<7 && b=="vert" ) output(" 1 /0 ")
if( a>=7&& a<10 && b=="vert" ) output(" 1 /0 ")
if( a>=10&& a<25 && b=="vert" ) output(" 0.9651 /3.49 ")
if( a>=25&& b=="vert" ) output(" 1 /0")
if( a>=3&& a<5 && b=="other" ) output(" 0.9922 /0.78 ")
if( a>=5&& a<7 && b=="other" ) output(" 0.9863 /1.37")
if( a>=7&& a<10 && b=="other" ) output(" 1 /0 ")
if( a>=10&& a<25 && b=="other" ) output(" 0.9719 /2.81 ")
if( a>=25&& b=="other" ) output(" 1 /0 ")
};
function output(str)
{
var arrj = str.split("/");
var one_br_risk = parseFloat(arrj[0]);
var life_eapectancb = parseFloat(window.document.getElementById('life_eapectancb').value);
var cum_riskj="--";
var five_br_risk="--"
{
five_br_risk = arrj[1];
cum_riskj = Math.round(((1-Math.pow((one_br_risk), life_eapectancb))*100)*10)/10;
}
window.document.getElementById('r2j').value=five_br_risk;
if(life_eapectancb<1)
cum_riskj="--";
if(cum_riskj===0)
cum_riskj="0*";
window.document.getElementById('r1j').value=cum_riskj;
};
}());
</script>
<br>
<form action="" id="riskformj" onSubmit="return false;">
<fieldset>
<label for="loc">Location</label>
<select id="location_Jp" name='location_Jp'
onchange="getRiskJp()">
<option value="mca">Middle cerebral</option>
<option value="aca">Anterior communicating</option>
<option value="ica">Internal carotid</option>
<option value="icapcomm">Internal carotid - posterior communicating</option>
<option value="bassca">Basilar tip / superior cerebellar</option>
<option value="vert">Vertebral / PICA / vertebrobasilar junction</option>
<option value="other">Other location</option>
</select>
<br>
<br>
<p>
<label class="inlinelabel" for='includeinscription'>
Size(mm) (minimum 3mm)</label>
<input type="text" id="An_Size_Jp" size=7 onKeyUp="getRiskJp()"
name="sizejp" value="0" />
<p>
<label class="inlinelabel" for='includeinscription'>
Life expectancy (minimum 1 year)</label>
<input type="text" id="life_eapectancb" size=7 onKeyUp="getRiskJp()"
name="sizejp" value="0" />
</p>
<br>
<p>
<label for="Five_bear">1 year Rupture Risk (%)</label>
<input type="text" name="val3jp" id="r2j"><span id="result2jp"></span>
<p>
<label for="One_bear">Cumulative Lifetime Rupture Risk (%)</label>
<input type="text" name="val3jp" id="r1j"><span id="result1jp"></span>
<div id="Final_Risk_Jp"></div>
</fieldset>
</form>
最佳答案
所以看来您没有在代码周围使用闭包,这很重要,因为不在闭包中的任何代码都是全局的。因此,现在两个 output
函数都存在......但浏览器使用哪个......这是任何人的猜测。闭包看起来像这样:
(function(){
"use strict";
window.getRisk = function(){ your code };
function output() {your code };
}());
(function(){
"use strict";
window.getRiskJp = function() { your code };
function output(){ your code };
}());
请注意,我正在定义需要在窗口对象的闭包外部可见的函数,否则它们对于回调将不可见。
关于javascript - Drupal block - 两个独立工作的 javascript,因为 block 放在同一页面上时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17307428/
我如何使用 CQLINQ 获取当前方法的输入参数集合?有像“参数”或“参数”这样的集合,只有“NbParamenter”不适合我的目的。 最佳答案 事实上,CQLinq 还没有这个功能。但是,在许多情
我想知道是否有人知道我的 makefile 中独立的 @ 符号和“dir”命令在这里(第二行和第三行)的作用: $(BUILD)/%.o: %.cpp @mkdir -p $(dir $@)
我想知道是否有人知道我的 makefile 中独立的 @ 符号和“dir”命令在这里(第二行和第三行)的作用: $(BUILD)/%.o: %.cpp @mkdir -p $(dir $@)
我的机器上有带有 4 个 cpu 的 Ubuntu 14.04(nproc 恢复了 4 个)。我安装并执行 Spark Standalone 后(本地),我可以自己定义不同数量的奴隶。例如我想要有4个
我看到所有这些 iPhone 应用程序都带有内置的独立 webDav 服务器。是否有可以集成到现有应用程序中的独立(如在其自己的 IIS 中)C# webDAV 项目。 最佳答案 至少有两个用于 .N
我如何在独立的 Django 应用程序上进行迁移(即不属于任何项目的应用程序)。 例如在以下之后:https://docs.djangoproject.com/en/1.8/intro/reusabl
我目前正在使用 tortoiseSVN 对本地编程文件进行版本控制。我不运行 SVN 服务器,因为可以直接使用 tortoiseSVN(例如 http://invalidlogic.com/2006/
我有一些 Bootstrap 代码,当用户查看它时,它可以很好地为进度条部分设置动画。 然而它动画 全部 页面中的进度条而不是动画仅限 该查看部分中的进度条。结果,当用户转到进度条的另一部分时,这些已
我认为我们在 iOS 13.2/13.3 中发现了关于在独立模式下运行的 PWA 的回归。 由于在 iOS PWA 上无法访问 getUserMedia() 我们依赖 capture HTML5 输入
我有一个每周从系统运行一次的报告,并将数据导出到 Excel 文档中。我已经设置了将数据导出到 Excel 的工具,以便在格式化方面做得很好,但是一旦数据进入 Excel,我还需要做更多的事情。 是否
//值数组的格式为 { "var1", "val1", "var2", "val2",.. } public static String replaceMethod(String template,
当我在 eclipse 中运行我的项目时,它工作正常,当我将它导出为独立 jar 时,它会滞后。我使用相同的 vmargs,在 Eclipse 中尝试了 3 种不同的导出设置,似乎没有任何帮助 最佳答
我了解到 Java EE 中我非常喜欢的注释基础配置(@Resource)功能。然后我注意到注释实际上是 Java SE 的一部分。 所以我想知道是否可以将它与 Java SE 一起使用。我当然可以在
我无法理解为什么这种关系没有被持久化,并且程序不会正常退出,但在 Eclipse 中继续运行。 下面是我的代码,排除了包名: 主要: import java.io.BufferedInputStrea
我有一个在 Linux + Java 6 上运行的独立 Java 应用程序,它似乎被卡住了(没有生成日志)我如何在不使用任何其他工具(例如 jstack)的情况下获取此线程转储 尝试了以下命令,但它们
我正在非节点环境中构建应用程序,但我想利用 Babel 的 ES6 转译,以便我可以编写更好的代码并且仍然支持 IE11。 所以我继续包含在这里找到的独立文件: https://github.com/
扩展我对 MySQL 的理解。 1) 是否需要 64 位帮助?我是安装还是单独使用? 2) 如果我打算在 MySQL Community Service 中使用 64 位,它会影响仅提供 32 位的
我有一个独立的 Java 应用程序,我必须为其集成一个规则引擎。我应该使用属性文件或 XML 文件定义规则。我需要规则引擎来读取属性或 XML 文件中定义的这些规则,并相应地在应用程序中实现代码。 任
我是wiremock新手,我正在尝试使用它来记录我负责集成测试的java应用程序的请求和响应。 我知道我的命令将类似于: java -jar wiremock-1.57-standalone.jar
我到处寻找我的问题的解决方案,但我的问题有点具体...我需要有关如何创建独立 radioGroup 列表的建议,例如图示: o item1 • item1' • item2 或 item2' o it
我是一名优秀的程序员,十分优秀!