单击链接时启动Jquery函数
我已经尝试了一段时间,我找不到解决办法,希望你能帮我 我有一个像这样的youtube视频链接单击链接时启动Jquery函数,jquery,function,hyperlink,Jquery,Function,Hyperlink,我已经尝试了一段时间,我找不到解决办法,希望你能帮我 我有一个像这样的youtube视频链接 <a id='LinkClick1' href='www.youtube.com' target='_blank'><strong>Title</strong></a> 我如何使我的链接点击打开网站,但也触发一个功能 谢谢。另一个演示。。。有问题的评论中提到的popover内的链接 相关代码 var img = '<a href="htt
<a id='LinkClick1' href='www.youtube.com' target='_blank'><strong>Title</strong></a>
我如何使我的链接点击打开网站,但也触发一个功能
谢谢。另一个演示。。。有问题的评论中提到的popover内的链接 相关代码
var img = '<a href="https://si0.twimg.com/a/1339639284/images/three_circles/twitter-bird-white-on-blue.png" target="_blank" id="1">TEST</a>';
$("#blob").popover({
trigger: "manual",
content: img
}).on("click", function(e) {
e.preventDefault();
}).on("mouseenter", function() {
$(this).popover("show");
$(this).siblings(".popover").on("mouseleave", function() {
$(this).hide();
});
}).on("mouseleave", function() {
var _this = this;
setTimeout(function() {
if (!$(".popover:hover").length) {
$(_this).popover("hide")
}
}, 100);
});
$(document).on('click', '#1',function(){
console.log("CLicked");
});
您可以使用
#LinkClick1
的父对象的选择器,而不是$(文档)
,您的代码正是这样做的:除了控制台。log
之外,我在单击函数中没有看到函数调用。你是说当你点击链接时,console.log
没有启动吗?我怀疑你分配“click”处理程序的代码是在
元素添加到DOM之前运行的。将您的
移动到
的末尾。将您的代码添加到$(文档)中。就绪(function(){..}
您的链接是否在运行时添加(通过ajax)?+1用于事件委派,而不是cookie cuter“将其放入.ready()中”
var img = '<a href="https://si0.twimg.com/a/1339639284/images/three_circles/twitter-bird-white-on-blue.png" target="_blank" id="1">TEST</a>';
$("#blob").popover({
trigger: "manual",
content: img
}).on("click", function(e) {
e.preventDefault();
}).on("mouseenter", function() {
$(this).popover("show");
$(this).siblings(".popover").on("mouseleave", function() {
$(this).hide();
});
}).on("mouseleave", function() {
var _this = this;
setTimeout(function() {
if (!$(".popover:hover").length) {
$(_this).popover("hide")
}
}, 100);
});
$(document).on('click', '#1',function(){
console.log("CLicked");
});
<a class="popup-marker btn" data-content="Click outside the popover to close it." data-original-title="Popover A" href="youtube.com" target="_blank">Click me (A)</a>
jQuery(function() {
$('.popup-marker').popover().on('click', function(e) {
// if any other popovers are visible, hide them
var a='Hi!';
var clicked='yes';
console.log(a+clicked);
});
});
$(document).on('click','#LinkClick1',function(){
var a='Hi!';
var clicked='yes';
console.log(a+clicked);
});