javascript 函数中的 sIFR 和 document.write
我正在尝试通过 javascript 循环设置一些 html 的样式,该循环通过 document.write(); 输出 html 功能。 我的 CSS 样式似乎正确显示,但是我的 sifr 类由于某种原因没有调用我的 flash 文件。 我想这可能与我正在使用的 javascript document.write 函数有关。
我想知道是否可以通过这种方式使用 SIFR。 如果没有,除了我所做的事情之外,还有其他选择吗?
这是我的代码:(基本上,我从 XML 文件加载数据并使用 document.write 将其输出为 HTML - 我已将我所引用的代码片段加粗。我是一名尝试编写 javascript 的设计师,所以在分解我的函数之前请记住这一点 =)
document.write("<h1 class="h1_sifr_green">Tours in the <br />");
document.write(search_term.toUpperCase());
document.write(" area:</h1><br /><br />");
再次,我的 h1 标签以及除 sifr 类之外的所有其他 css 类都很好。 预先感谢,非常感谢这里的任何帮助。
这是我的完整代码:
<html>
<head>
<link href="../css/colors.css" rel="stylesheet" type="text/css" />
<link href="../css/layout.css" rel="stylesheet" type="text/css" />
<link href="../css/textstyles.css" rel="stylesheet" type="text/css" />
<link href="../css/sifr.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/sifr.js"></script>
<script type="text/javascript" src="js/sifr-config.js"></script>
<script type="text/javascript">
function parseXML()
{
var search_term=window.location.search.substring(1); //sets the search_term variable to the URL string query
var tour_name;
var tour_link;
var tour_logo;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load(search_term + ".xml");
x=xmlDoc.documentElement.childNodes;
document.write("<h1 class=\"h1_sifr_green\">Tours in the <br />");
document.write(search_term.toUpperCase());
document.write(" area:</h1><br /><br />");
for (i=0;i<x.length;i++)
{
tour_name=xmlDoc.getElementsByTagName("name")[i].firstChild.nodeValue;
tour_link=xmlDoc.getElementsByTagName("tourlink")[i].firstChild.nodeValue;
document.write("<a href=\"" + tour_link + "\" class=\"b3 textlink\">" + tour_name + "</a>");
document.write("<br />");
}
}
</script>
</head>
<body>
<div id="wrap" style="background-image:url(../images/index_06.jpg); width:550px">
<div style="padding:30px">
<script type="text/javascript" language="JavaScript">
parseXML();
</script>
</div>
</div>
</body>
</html>
I am trying to style some html through a javascript loop which outputs the html through the document.write(); function. My CSS styles seem to come through correctly, however my sifr classes are not calling my flash file for some reason. I was thinking it might have something to do with the javascript document.write function I am using.
Id like to know if it is possible to use SIFR in this way. If not, does anyone have any alternatives to what Im doing?
Here is my code: (basically, I am loading data from an XML file and outputting it as HTML with document.write - I have bolded the piece of code that I am reffering to. I am a designer who trys to write javascript, so keep that in mind before tearing apart my function. =)
document.write("<h1 class="h1_sifr_green">Tours in the <br />");
document.write(search_term.toUpperCase());
document.write(" area:</h1><br /><br />");
Again, my h1 tag comes through fine, as well as all my other css classes EXCEPT my sifr class. Thanks in advance, any help here is appreciated.
Here is my code in it's entirety:
<html>
<head>
<link href="../css/colors.css" rel="stylesheet" type="text/css" />
<link href="../css/layout.css" rel="stylesheet" type="text/css" />
<link href="../css/textstyles.css" rel="stylesheet" type="text/css" />
<link href="../css/sifr.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/sifr.js"></script>
<script type="text/javascript" src="js/sifr-config.js"></script>
<script type="text/javascript">
function parseXML()
{
var search_term=window.location.search.substring(1); //sets the search_term variable to the URL string query
var tour_name;
var tour_link;
var tour_logo;
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load(search_term + ".xml");
x=xmlDoc.documentElement.childNodes;
document.write("<h1 class=\"h1_sifr_green\">Tours in the <br />");
document.write(search_term.toUpperCase());
document.write(" area:</h1><br /><br />");
for (i=0;i<x.length;i++)
{
tour_name=xmlDoc.getElementsByTagName("name")[i].firstChild.nodeValue;
tour_link=xmlDoc.getElementsByTagName("tourlink")[i].firstChild.nodeValue;
document.write("<a href=\"" + tour_link + "\" class=\"b3 textlink\">" + tour_name + "</a>");
document.write("<br />");
}
}
</script>
</head>
<body>
<div id="wrap" style="background-image:url(../images/index_06.jpg); width:550px">
<div style="padding:30px">
<script type="text/javascript" language="JavaScript">
parseXML();
</script>
</div>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当你的 .js 文件链接不正确时,我一定会喜欢...链接已损坏,链接已修复,问题已解决。
Yep, gotta love when your .js files are not linked correctly... link was broken, fixed link, problem solved.