图标图像没有被javascript代码挑选 [英] icon image not getting picked in javascript code

查看:112
本文介绍了图标图像没有被javascript代码挑选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:



RAD 7.5,WebSphere 6.1



使用Maven构建应用程序。



MyApp - > src ---> main ---> resources

  ---> webapp 

webapp文件夹还包含JSP文件夹,images文件夹,jscript文件夹,WEB-INF,
在我的图像文件夹中有一个图标文件夹,其中包含所有图标,如search_result.png



我在jscript文件夹中的someJavascript.js中的javascript代码如下所示:

  for(var p = 0; p< tabLists.length; p ++){
var anchor = tabLists [p] .firstChild;
var iconFile;

if(tabLists [p] .firstChild.innerHTML ==Search Result)
{
iconFile ='../ images/icons/search.PNG';

}

else if(tabLists [p] .firstChild.innerHTML ==Core Details)
{
iconFile ='../图像/图标/ details.png';
}

anchor.style.backgroundImage ='url('+ iconFile +')';
anchor.style.backgroundRepeat ='no-repeat';
anchor.style.backgroundPosition ='1px 2px';
anchor.className ='toplevel-tab';
}

然而,图片未显示。



我错过了什么?



感谢您阅读!!

解决方案

如果图像没有加载,你可以做的绝对最好的事情是弄清楚实际被请求的路径。这样做有两件事情绝对会让你失望。



1。)Apache Access Logs。



2.。)Win32的尾巴。该程序是一个实时日志监视器。我高度建议使用文本颜色选项(设置[菜单] - >关键字)来突出显示示例和基于WRITE的MySQL查询中的HTTP 404错误(DELETE,INSERT和UPDATE )。请注意,关键字在您应用它们之后应用,然后触发它(程序不会返回突出显示已执行的前一行)。有时候我注意到日志稍微延迟了不到10秒就可以更新日志,但通常每隔一到三秒更新一次。



这是当然假设您正在运行Windows的副本,它基于UNIX -f命令或其他东西(请参阅他们的主页),所以如果您不使用的话,您很有可能找到执行此操作的非Windows应用程序基于Windows的操作系统。



当你在访问日志中发现404错误时(顺便提一下apache / logs / access.log路径)比较404 REQUEST的FULL路径到了ACTUAL路径的完整路径然后你将有一个很大的线索,你需要修复什么(例如,太多../).



我还强烈建议使用XHTML基本元素并将其设置为站点的基本索引,然后设置var path ='';匹配它。使用服务器端语言(例如PHP)来确定正确的路径,并且您可以使用完全相同的软件副本轻松地在BOTH localhost和example.com(实时域)上获得与FLAWLESSLY一起运行的完全相同的副本。 / p>

所有这些都是我运行和维护个人网站的方式(在我的个人资料中链接)。我会尽力澄清你需要的任何东西。


Environment:

RAD 7.5, WebSphere 6.1

Building the application using Maven.

MyApp --> src ---> main ---> resources

                   --->  webapp

The webapp folder is further having the JSP folder, images folder, jscript folder, WEB-INF, etc. etc. In my images folder there is a icons folder with all the icons like search_result.png

My javascript code in someJavascript.js in jscript folder is as below:

for (var p = 0; p < tabLists.length; p++) { 
    var anchor = tabLists[p].firstChild; 
    var iconFile;

if(tabLists[p].firstChild.innerHTML == "Search Result")
   {
    iconFile = '../images/icons/search.PNG'; 

   }

else if(tabLists[p].firstChild.innerHTML == "Core Details")
{
    iconFile = '../images/icons/details.png';
 }

anchor.style.backgroundImage = 'url(' + iconFile + ')'; 
anchor.style.backgroundRepeat = 'no-repeat';        
anchor.style.backgroundPosition = '1px 2px';        
anchor.className = 'toplevel-tab';
} 

However, the image is not getting displayed.

What am I missing ??

Thanks for reading!!

解决方案

If the image is not loading the absolute best thing you can do is figure out the path that's actually being requested. There are two things that will absolutely blow you away in doing that.

1.) Apache Access Logs.

2.) Tail for Win32. This program is a REAL TIME LOG MONITOR. I highly recommend using the text color options (Settings [menu] --> Keywords) to highlight HTTP 404 errors in example and WRITE based MySQL queries (DELETE, INSERT and UPDATE). Note that the keywords apply AFTER you've applied them and then something triggers it (the program won't go back to highlight previous lines already executed). Also on occasion I've noticed a slight delay of upwards to just under ten seconds for the log to update though usually it updates once every one to three seconds.

This is of course presuming you're running a copy of Windows, it's based off of a UNIX -f command or something (see their homepage) so it's exceptionally likely you can find a non-Windows application that does this if you're not using a Windows based OS.

When you find the 404 error in the access log (apache/logs/access.log path by the way) compare the FULL path of the 404 REQUEST to the full path of the ACTUAL path and then you'll have a big fat clue as to what you need to fix (e.g. one too many ../).

I also highly recommend using the XHTML base element and setting it to the base index of your site and then setting a var path = ''; to match it. Use a server-side language (e.g. PHP) to determine the correct path and you can EASILY get the EXACT same copy of your site running FLAWLESSLY on BOTH localhost and example.com (live domain) using the exact same copy of your software.

All of this is how I run and maintain my personal site (linked in my profile). I'll try to clarify anything you need.

这篇关于图标图像没有被javascript代码挑选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆