简体   繁体   English

Javascript未在一页上加载,而在另一页上运行良好

[英]Javascript not loading on one page, works fine on another

I have the following piece of javascript on one of my pages 我的其中一个页面上有以下javascript代码

<script type="text/javascript">
var state = 'none';
function showhide(layer_ref, badgeid, location) {
    alert("Run")
    if (state == 'block') {
        state = 'none';
    }
    else
    {
        state = 'block';
    }

    hza = document.getElementById(layer_ref);
    hza.style.display = state;

    if (state == 'block') {
        badgeinfo(badgeid, location);
    }
}
</script>

its called using 它称为

<td width="50%" align="right" valign="middle" onclick="showhide('id215', '215', 'req_215');"><img src="/images/badges/2015be-cs-csa.png" width="100" height="100" alt="Chief Scout's Bronze Award" /></td>

One on page its loads fine, i get the alert when i click the image, but on another page, nothing happens, the alert isn't shown. 在一页上加载效果很好,当我单击该图像时会收到警报,但是在另一页上却什么也没有发生,因此不会显示该警报。

The page is dynamically produced based on a couple of variables which define what section is loaded. 该页面是基于几个变量的动态生成的,这些变量定义了加载哪个部分。 Even if i change the javascript function to just the alert it doesn't do anything. 即使我将javascript函数更改为警报,它也不会执行任何操作。 If i change the section of the badges in the database so they load on another page its fine, and previously working badges if they are on this section don't load 如果我更改了数据库中的徽章部分,以便它们可以很好地加载到另一页上,并且以前在此部分中工作的徽章也不会加载

This is the non working page http://new.wgcscouts.co.uk/test1.php 这是非工作页面http://new.wgcscouts.co.uk/test1.php

And this is a working one http://new.wgcscouts.co.uk/test2.php 这是一个有效的http://new.wgcscouts.co.uk/test2.php

In the working example, there is an index number appended to the section url... 在工作示例中,在部分url后面附加了一个索引号...

url=url+"&amp;section="+1;

The number at the end of line 51 is not being populated in the non-working example 在非工作示例中,不会填充第51行末尾的数字

url=url+"&amp;section="+;

That is a syntax error for javascript, which then stops executing as it can't parse the input. 这是javascript的语法错误,由于无法解析输入内容,因此该脚本停止执行。

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

相关问题 Javascript弹出窗口在一页上有效,但在另一页上无效 - Javascript popup window, works on one page, but not on another 奇怪的JavaScript行为,适用于一个页面,但不适用于另一个页面 - Weird javascript behaviour, works on one page but not another 为什么 javascript 脚本没有在一个 wordpress 页面上运行,但在另一个页面上运行良好? - Why is a javascript script not running on one wordpress page, but working fine on another? JavaScript关闭按钮在一页上有效,但在另一页上无效 - JavaScript close button works on one page, but not on another page Materializecss菜单仅在一个页面上正常工作 - Materializecss menu works fine only on one page jQuery在JSP页面中不起作用,但是javascript正常工作 - JQuery not working in JSP page but javascript works fine jQuery 的新手 - 无法找出为什么 AJAX 脚本在一个页面上工作正常,但在另一个页面上却不行 - New to jQuery - having trouble finding out why an AJAX script works fine on one page, but not on another 从javascript中的字符串加载XML在IE 8中工作正常,在Firefox中失败 - Loading XML from string in javascript works fine in IE 8, fails in firefox 从带有JavaScript的另一个页面加载带有javascript的页面 - Loading a page with javascript from another page with javascript Javascript没有将其他页面加载到DIV中 - Javascript not loading another page into DIV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM