2017-05-03 146 views
-2

你可以幫助我與加號「+」的含義之前和之後myUrl在功能.not。爲什麼+在屬性href功能。不

它可以正常使用+或無+,所以爲什麼這本書使用它們?

<script type="text/javascript"> 
 
$(document).ready(function() { 
 
    $('a[href^="http://"]').each(function() { 
 
     var href = $(this).attr('href'); 
 
     $(this).after(' {' + href + '}'); 
 
    }); 
 

 
    //$('a[href^="http://"').attr('target','_blank'); 
 
    var myUrl = location.protocol + '//' + location.hostname; 
 
    $('a[href^="http://"], a[href^="https://"]').not('[href^="' + myUrl + '"]').attr('target', '_blank'); 
 
}); 
 
</script>

+3

我懷疑它沒有使用'+'。 ['+'執行*字符串連接*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition_())。 –

+2

RTFM請,_ + _是JavaScript級聯標誌.. –

+1

絕對沒有'+' –

回答

0

這是事實。 '+'僅用於連接字符串。

你可能會看到它的工作沒有理由「+」可能是由於您的瀏覽器應用程序能夠直接發佈針對「=」符號值(智能瀏覽器EHH!)。在Microsoft IE中嘗試不使用'+'即可看到它的工作方式不同;)。

相關問題