我在下面的代码中遇到了问题,
MyConfig.js (这是一个外部js文件)
function myFunction()
{
var tfile = "file://";
// Server Location(should be changed at the time of deployment)
var location = "inhyds149";
// Document folder location. The user documents will be pulled from here.
var staticpath = "/Documents/pdfs/";
var n=tfile.concat(location,staticpath);
return n;
}我的HTML内容::
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Adobe RoboHelp 10" />
<title>Third</title>
<link rel="StyleSheet" href="default.css" type="text/css" />
<script src="D:\Test\MyConfig.js" type="text/javascript"/>
</head>
<body>
<script>
function myFinal()
{
var tfile1 = myFunction();
var location1 = "Holidays 2013.pdf";
// Document folder location. The user documents will be pulled from here.
var n1=tfile1.concat(location);
return n1;
}
</script>
<h1>Third</h1>
<p>Dynamically hyperlink pdf to <span style="font-weight: bold;">'welcome'</span>
keyword</p>
<p> </p>
<p><a id="Link" onclick="myFinal()" target="_blank">Welcome</a></p>
</body>
</html>我的要求是将从外部js文件中获得的结果与js文件中location1中的值连接起来,并在单击时将其提供给它。请帮帮忙。
实际上,要求是我需要动态生成一个位置。因此,外部JS函数将包含路径的一部分,而内部JS函数将包含其余部分。我只想把它们连接起来,然后打开那个PDF。因此,它将是myFunction将返回说: //abc/xyz,我将在我的html中有一个字符串,我必须合并它们,说: //abc/xyz/l.pdf我只想打开这个pdf
发布于 2013-10-10 17:07:35
更改此设置:
<script src="D:\Test\MyConfig.js" type="text/javascript"/>要这样做:
<script src="MyConfig.js" type="text/javascript"/>发布于 2013-10-10 17:12:47
脚本路径的路径应该是相对路径,而不是绝对路径。
它应该是这样的
<script src="foldername/MyConfig.js" type="text/javascript"/>另外,你使用的是锚标签和onclick,所以你的函数应该返回false。
https://stackoverflow.com/questions/19291463
复制相似问题