Javascript 如何使href和jquery单击事件都起作用
我有一个报告功能Javascript 如何使href和jquery单击事件都起作用,javascript,jquery,click,Javascript,Jquery,Click,我有一个报告功能answercardinerlinkreportingcall,单击可以调用该功能。如果出现提示,请登录 显示1个步骤中的1个。 您可以使用javascript: window.location.href = 'http://url.here.com'; 告诉浏览器导航到某个页面。希望能有帮助 另一种方法是从answerCardInnerLinkReportingCall返回true或false,具体取决于调用或不调用事件。PreventDefault() 试试这样的方法: $
answercardinerlinkreportingcall
,单击可以调用该功能。如果出现提示,请登录
显示1个步骤中的1个。
您可以使用javascript:
window.location.href = 'http://url.here.com';
告诉浏览器导航到某个页面。希望能有帮助
另一种方法是从answerCardInnerLinkReportingCall返回true或false,具体取决于调用或不调用事件。PreventDefault() 试试这样的方法:
$('#answerCard a').click(function(event) {
var loc = $(this).attr('href');
event.preventDefault();
answerCardInnerLinkReportingCall(loc, this);
});
function answerCardInnerLinkReportingCall(loc, that){
// your code to do stuff here
window.open(loc, '_blank');
}
请参见我想您不需要使用任何“event.preventDefault();”如果要在脚本执行后使用链接本机功能 像这样试试
jQuery(document).on('click','#answerCard a', function(event) {
//event.preventDefault();
alert('script running');
answerCardInnerLinkReportingCall(this);
});
还创建了。检查一下。你能包括HTML吗?我就是这样做的
$('#answerCard a').click(function(event) {
var loc = $(this).attr('href');
event.preventDefault();
answerCardInnerLinkReportingCall(loc, this);
});
function answerCardInnerLinkReportingCall(loc, that){
// your code to do stuff here
window.open(loc, '_blank');
}
jQuery(document).on('click','#answerCard a', function(event) {
//event.preventDefault();
alert('script running');
answerCardInnerLinkReportingCall(this);
});