在這裏,我有這樣的http://www.thidiff.com/&sa=U&ved=0ahUKEwiexM7XmaPRAhWmrVQKHUmXDXMQ_BcIYygBMBA&usg=AFQjCNEf9K9tDpISjuX1qkTOHK_aeiPrwQ
我怎樣才能獲得網址前面的與
鏈接我想是http://www.thidiff.com/
這&
之前如何是可以做到的
我有樣hrefs
$('a.ganna').each(function(){
var href = $(this).attr('href');
var ampIndex = href.indexOf('&');
console.log(ampIndex);
var httIndex = href.indexOf('htt');
console.log(httIndex);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<a class="ganna" href="/url?q=http://www.thidiff.com/&sa=U&ved=0ahUKEwiexM7XmaPRAhWmrVQKHUmXDXMQ_BcIYygBMBA&usg=AFQjCNEf9K9tDpISjuX1qkTOHK_aeiPrwQ">Website</a>
<a class="ganna" href="/url?q=http://www.sahasraadvisoryagency.com/&sa=U&ved=0ahUKEwjOxOnmmaPRAhUHh1QKHRR3B4cQ_BcIVCgBMA4&usg=AFQjCNFIbN_BcKr1501xZcqpER22-Bfy4A">Website</a>
我的預期輸出:
http://www.thidiff.com/
http://www.sahasraadvisoryagency.com/
@baao,請確認這個'與'答案是非常不同的question'問題是關係匹配字符串的切割' – EaB