我有一个JavaScript链接引用另一个.js文件。我一直在试图输出一个图像(用于测试目的),但我不确定什么是正确的方式去做这件事。使用javascript输出html
alert("beginning");
//var link = $("<a href='http://juixe.com'>Hello, <b>World</b>!</a>");
//$('body').append(link);
//document.write("hi");
//document.write("<div><img src='http://s3-media2.ak.yelpcdn.com/bphoto/xqC6Iy5mOLb_8mwMKGv8_w/l.jpg' /></div>");
alert("before function");
(function(){
alert("middle");
var links = $("<a href='http://juixe.com'>Hello, <b>World</b>!</a>");
$('body').append(links);
alert("after middle");
//alert($("img").attr("id"));
document.write("hi");
document.write("<div><img src='http://s3-media2.ak.yelpcdn.com/bphoto/xqC6Iy5mOLb_8mwMKGv8_w/l.jpg' /></div>");
alert("end");
}());
我能够提醒开始,一直到中间。好像var links
不起作用。我试图在.js
文件中使用HTML。本质上,我想能够做一些模态窗口,但我现在试图输出用于测试目的的图像。
此外,这是jquery的正确方法?
在此先感谢!
“在加载页面后永远不能使用document.write”。我只是试图在控制台中,看起来像它可以使用,但取代整个页面:) – sabithpocker
@sabithpocker刚好点 – charlietfl
刚刚阅读此,https://developer.mozilla.org/en/document.write它显示了一个例子页面加载后用document.write替换页面。只是好奇你的评论;) – sabithpocker