$('a').click(function () {
if ($(this).attr('id') !== '_blank') {
window.location.href = $(this).attr('href');
}
});
上面的代码在PhpStorm中显示一条警告消息:
分配的表达式类型jQuery不能分配给类型字符串
我该如何解决?
答案 0 :(得分:-1)
此代码适用于Chrome。
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
</head>
<body>
<a href="https://www.google.com">Google</a>
<script>
(function(){
$('a').click(function () {
if ($(this).attr('id') !== '_blank') {
window.location.href = $(this).attr('href');
}
});
})();
</script>
希望有所帮助