您好,想知道我是否可以获得帮助。我得到了以下脚本,它已经获取了我正在尝试操作的标签。我想让标签或节点值可点击。我该如何去做呢?
$(document).ready(function () {
var calMonth = document.getElementsByClassName("fc-header-title");
var fcalendarLink = "http://www.google.com";
for (var i = 0 ; i < calMonth.length; i++) {
var h2Tag = calMonth[i].getElementsByTagName('h2')[0];
var h2TagValue = h2Tag.innerHTML;
}
console.log(h2Tag);
console.log(h2TagValue);
});
最佳答案
可以设置onclick事件:
$(document).ready(function () {
var calMonth = document.getElementsByClassName("fc-header-title");
var fcalendarLink = "http://www.google.com";
for (var i = 0 ; i < calMonth.length; i++) {
var h2Tag = calMonth[i].getElementsByTagName('h2')[0];
var h2TagValue = h2Tag.innerHTML;
added >>> h2Tag.addEventListener('click', function() {
added >>> alert('clicked');
added >>> }
}
console.log(h2Tag);
console.log(h2TagValue);
});
您可能还想使用 CSS 将光标更改为指针。像这样的事情:
.h2 {
cursor: pointer;
}
关于javascript - 通过js使标签可点击URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653882/