我想预览内容,当我点击 anchor 标记时,
var profiledemo = profiles.split(",");
for (var pd = 0; pd < profiledemo.length; pd++) {
var mydiv = document.getElementById("Profile");
var aTag = document.createElement('a');
aTag.setAttribute('href');
aTag.innerHTML = profiledemo[pd];
mydiv.appendChild(aTag);
aTag.onclick = function () {
alert("profiles anchor tag called");
}
}
我能够显示多个文档,对于这些文档,我在上面使用了 anchor 标记,现在我想要,当用户单击特定标记时,我必须显示数据库中的文档内容。
最佳答案
在纯 JavaScript 中绑定(bind)事件不太方便,因为 IE 和其他浏览器提供不同的 API,因此您必须检查浏览器类型并保持跨浏览器兼容性。 你最好使用 jQuery。
$(aTag).click(function() { alert("..."); });
顺便问一下,是否有必要以编程方式构建 anchor ?我建议嵌入 html anchor 并在必要时显示。
关于javascript - 如何使用 anchor 标记显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13097114/