Javascript jquery获取href并将其传递给函数
我在获取点击元素的href并将其传递给函数时遇到了一些问题,这是我以前没有做过的事情,所以我尽了最大努力,但没有做到。有什么想法吗Javascript jquery获取href并将其传递给函数,javascript,jquery,Javascript,Jquery,我在获取点击元素的href并将其传递给函数时遇到了一些问题,这是我以前没有做过的事情,所以我尽了最大努力,但没有做到。有什么想法吗 $('#smoke_confirm').click(function(e){ var href = $(this).attr("href"); tstconfirm(href); e.preventDefault(); }); function tstconfi
$('#smoke_confirm').click(function(e){
var href = $(this).attr("href");
tstconfirm(href);
e.preventDefault();
});
function tstconfirm(href){
smoke.confirm('Are you sure you want to delete?',function(e){
if (e){
window.location = $(href);
}
}, {cancel:"cancel", ok:"confirm"});
}
href
是一个字符串
window.location = $(href); // This will try to convert it to a jQuery object
应该是
window.location = href;
href
是一个字符串
window.location = $(href); // This will try to convert it to a jQuery object
应该是
window.location = href;
href此处是一个文本,所以
$(href)
不正确,因为它将尝试使用href值选择元素。只需执行window.location=href
。另外,如果您只想获取href,则不需要创建this
的jquery实例,您只需执行作为DOM元素属性的this.href
$('#smoke_confirm').click(function(e){
var href = this.href;
tstconfirm(href);
e.preventDefault();
});
function tstconfirm(href){
smoke.confirm('Are you sure you want to delete?',function(e){
if (e){
window.location = href;
}
}, {cancel:"cancel", ok:"confirm"});
}
href此处是一个文本,所以
$(href)
不正确,因为它将尝试使用href值选择元素。只需执行window.location=href
。另外,如果您只想获取href,则不需要创建this
的jquery实例,您只需执行作为DOM元素属性的this.href
$('#smoke_confirm').click(function(e){
var href = this.href;
tstconfirm(href);
e.preventDefault();
});
function tstconfirm(href){
smoke.confirm('Are you sure you want to delete?',function(e){
if (e){
window.location = href;
}
}, {cancel:"cancel", ok:"confirm"});
}
问题是jQuery太多;)问题是jQuery太多;)非常感谢!我知道我就快到了:)@1Line不客气。是的,你只是打了个小嗝……)非常感谢!我知道我就快到了:)@1Line不客气。是的,你只是打了个小嗝……)