实际上我的页面中有5个脚本。我知道要将所有五个脚本保留在单个脚本标记中,但我需要它在单独的脚本中进行处理。我的问题是,在第一个脚本标记中,如果它是真的则存在一个条件然后运行剩余的脚本,但是当在页面顶部脚本中的第一个脚本返回false时,我也想停止执行重映射脚本。如果有任何想法,请提供帮助。
<script type="text/javascript">
//my code here if true then run the below scripts then stop executing the below script
</script>
<script type="text/javascript">
//my code here
</script>
<script type="text/javascript">
//my code here
</script>
<script type="text/javascript">
//my code here
</script>
<script type="text/javascript">
//my code here
</script>
答案 0 :(得分:2)
<script type="text/javascript">
var trueorfalse = true;
</script>
<script type="text/javascript">
if(trueorfalse == true){
//my code here
}else{
//my code here
}
</script>
答案 1 :(得分:1)
您可以在LocalStorage
中保存您的条件状态,并在每次继续之前进行检查。
如下所示:
<script type="text/javascript">
if(typeof(Storage) !== "undefined") {
if(yourCondition) {
localStorage.setItem("runForrestRun", true);
}
} else {
// Sorry! No Web Storage support..
}
</script>
<script type="text/javascript">
if(localStorage.runForrestRun) {
// execute your commands
}
</script>
<script type="text/javascript">
if(localStorage.runForrestRun) {
// execute your commands
}
</script>
<script type="text/javascript">
if(localStorage.runForrestRun) {
// execute your commands
}
</script>
<script type="text/javascript">
if(localStorage.runForrestRun) {
// execute your commands
}
</script>
答案 2 :(得分:1)
尝试将4个脚本中的每个脚本的内容包含在4个不同的功能中,然后从第一个脚本部分启动该功能