Javascript 来自PhpStorm的警告:指定的表达式类型jQuery不能分配给类型string
上面的代码在PhpStorm中显示一条警告消息: 分配的表达式类型jQuery不能分配给类型stringJavascript 来自PhpStorm的警告:指定的表达式类型jQuery不能分配给类型string,javascript,jquery,html,phpstorm,Javascript,Jquery,Html,Phpstorm,上面的代码在PhpStorm中显示一条警告消息: 分配的表达式类型jQuery不能分配给类型string 如何修复它?此代码与Chrome完美配合 $('a').click(function () { if ($(this).attr('id') !== '_blank') { window.location.href = $(this).attr('href'); } }); (功能(){ $('a')。单击(函数(){ if($(this.attr('id
如何修复它?此代码与Chrome完美配合
$('a').click(function () {
if ($(this).attr('id') !== '_blank') {
window.location.href = $(this).attr('href');
}
});
(功能(){
$('a')。单击(函数(){
if($(this.attr('id')!='\u blank'){
window.location.href=$(this.attr('href');
}
});
})();
希望对您有所帮助我逐字尝试了您的代码,似乎效果不错。您确定此代码段导致了警告吗?此外,这是否应该使带有
id=“\u blank”
的链接不执行任何操作?在这种情况下,请不要忘记添加e.preventDefault()
,其中e
是回调函数中的事件参数。等等,您使用的是TypeScript吗?我在phpstorm中对其进行了编码,警告信息不会显示在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>