简体   繁体   English

为什么此脚本永远不会运行?

[英]Why does this script never run?

I've got the following JavaScript statement, that executes on Page Load: 我有以下JavaScript语句,该语句在Page Load上执行:

The variable u1 is populated with one of the following values: 变量u1填充有以下值之一:

BBSLoan|Accept|PPI+No|60Months
BBSLoan|Refer|PPI+No|60Months
HSBSLoan|Accept|PPI+No|48Months
HSBSLoan|Refer|PPI+No|48Months

I have been informed that the conditions in the conditional statements will never be met - is this true? 我被告知永远不会满足条件语句中的条件-这是真的吗? From what I can see, going on each of the variables, the index that will be returned by indexOf is 0 ? 从我所看到的,继续每个变量, indexOf将返回的索引为0 Unless I am mistaken? 除非我弄错了?

EDIT: Just to clarify, the variable 'u1' will be populated dynamically with any of the 4 strings listed above. 编辑:只是为了澄清,变量'u1'将动态填充上面列出的4个字符串中的任何一个。 The %pu1=!; %pu1=!; is actually a macro that will populate this value. 实际上是一个将填充此值的宏。

<script language="JavaScript" type="text/javascript">
    var u1 = '%pu1=!;';

    if (u1.indexOf('BBSLoan|Accept') > -1) {
        var pvnPixel = '<img src="http://www.url1.com"/>';
        document.writeln(pvnPixel);
    }
    if (u1.indexOf('BBSLoan|Refer') > -1) {
        var pvnPixel2 = '<img src="https://www.url2.com;"/>';
        document.writeln(pvnPixel2);
    }
    if (u1.indexOf('HSBSLoan|Accept') > -1) {
        var pvnPixel3 = '<img src="https://www.url3.com;"/>';
        document.writeln(pvnPixel3);
    }
</script>

Thanks in advance! 提前致谢!

EDIT: Just to clarify, the variable 'u1' will be populated dynamically with any of the 4 strings listed above. 编辑:只是为了澄清,变量'u1'将动态填充上面列出的4个字符串中的任何一个。 The %pu1=!; %pu1 = !; is actually a macro that will populate this value. 实际上是一个将填充此值的宏。

This answer is not correct. 这个答案是不正确的。 It will be deleted later, but is being left to prevent this answer from popping up again. 稍后将其删除,但是将其保留以防止再次弹出此答案。

var u1 = '%pu1=!;';

The value of u1 is always '%pu1=!;' u1的值始终为'%pu1=!;' , since you declare it as that. ,因为您将其声明为那样。

好的,我终于使用search而不是indexOf

Would it make more sense to use a switch statement with a default case, or at a minimum provide an "else" with a default? 在默认情况下使用switch语句会更有意义,还是至少在默认情况下提供“ else”?

Have you tried to put a debugger statement in after var u1 is set, and step through using the client (firefox, chrome, IE, safari all have built in "developer tools" with the ability to step through js code) debugger to see what the value of u1 is? 您是否尝试过在设置了var u1之后放入调试器语句,并逐步使用客户端(firefox,chrome,IE,safari都内置了“开发人员工具”,能够逐步执行js代码)调试器来查看一下u1的值是多少?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM