来自PhpStorm的警告:分配的表达式类型jQuery不能分配给类型字符串

时间:2018-01-26 03:08:33

标签: javascript jquery html phpstorm

$('a').click(function () {
    if ($(this).attr('id') !== '_blank') {
        window.location.href = $(this).attr('href');
    }
});

上面的代码在PhpStorm中显示一条警告消息:

  

分配的表达式类型jQuery不能分配给类型字符串

我该如何解决?

1 个答案:

答案 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>

希望有所帮助