我有一个使用write语句创建文本的函数。我怎么能重写以下所以“here”这个词是一个可点击的锚标签?
href = www.example.com target = _blank id = link
.write("website:Click here to visit our website.",800)
答案 0 :(得分:0)
请参阅此How to add anchor tags dynamically to a div in Javascript?
var mydiv = document.getElementById("myDiv");
var aTag = document.createElement('a');
aTag.setAttribute('href',"www.example.com");
aTag.setAttribute('target',"_blank");
aTag.setAttribute('id',"link");
aTag.innerHTML = "link text";
mydiv.appendChild(aTag);
更新:使用Write()
document.write("website:Click <a href='http://www.google.com'
target='_blank' id='link'> here</a>to visit our website.");
答案 1 :(得分:0)
您可以使用
var mydiv =document.getElementById("myDiv");
mydiv.innerHTML = "click <a href='yourLinkAction'>here<\a> to go to website";
答案 2 :(得分:0)
基本上.write()
方法用于直接在HTML
上书写。所以在你写完之后你不能改变它。尝试以下方式,
function WriteNow(){
document.write("website:Click <a href='http://www.google.com/' target =_blank id ='link'>here</a> to visit our website.",800);
}
WriteNow();