Javascript相对路径
在第一个html文件中,我使用变量categoryLinks:Javascript相对路径,javascript,json,relative-path,Javascript,Json,Relative Path,在第一个html文件中,我使用变量categoryLinks: var categoryLinks = { 'Career prospects':'http://localhost/Landa/DirectManagers/511-HelenaChechik/Dim01.html', 'Compensation':'http://localhost/Landa/DirectManagers/511-HelenaChechik/Dim02.html',.... 在第二个html文
var categoryLinks = {
'Career prospects':'http://localhost/Landa/DirectManagers/511-HelenaChechik/Dim01.html',
'Compensation':'http://localhost/Landa/DirectManagers/511-HelenaChechik/Dim02.html',....
在第二个html文件中,我通过提取一些Json来创建一个图表:
$(function () {
var chart1;
$.get('graphdata/Dim1.txt?x='+microtime(), function(json){
obj = eval('({'+json+'})');
在这个Json中,有一行引用了类别链接,以指向相关的超链接:
labels: {
formatter: function () {
return '<a href="' + categoryLinks[this.value] + '">' +
this.value + '</a>';
},
style: {color: 'blue',textDecoration: 'underline',fontSize:'13px'}
}
这取决于加载它们的页面的URL,您尚未显示该URL,但您可能需要一个前导的
/
:
var categoryLinks = {
'Career prospects':'/Landa/DirectManagers/511-HelenaChechik/Dim01.html'
// Here ----------------^
…或可能是前导的。/
:
var categoryLinks = {
'Career prospects':'../Landa/DirectManagers/511-HelenaChechik/Dim01.html'
// Here ----------------^^^
…或类似的
基本上:
说你有
http://example.com/foo/page.html
如果您不想进入foo
,您可以使用前导的/
,意思是“从域的根开始”:
。
可以多次使用,因此如果您拥有该页面:
http://example.com/this/is/deeply/nested.html
http://example.com/this/is/deeply/nested.html
相对联系
../../test.html
../../test.html
给你
http://example.com/this/test.html
http://example.com/this/test.html
还要注意,链接将与它们所在的HTML页面相关,而不是它们所在的JavaScript脚本文件。
eval(“({'+json+')”)代码>。。。真正地我确实理解您为什么需要执行eval,因为您使用$.get获得的数据中有函数
,但是调用该数据json
要求(将来)获得的不是json而是普通的JavaScript。还要注意,链接将与它们所在的HTML页面相关,不是他们所在的JavaScript脚本文件。
-我认为这是问题的根源。两个页面处于同一个级别。我尝试过var categoryLinks={“职业前景”:“Landa/DirectManagers/511 helenachik/Dim01.html”…问题是,没有htttp://部分,我没有超链接格式
/testing/stuff.html
../testing/stuff.html
http://example.com/this/is/deeply/nested.html
../../test.html
http://example.com/this/test.html