2017-03-05 23 views
-3

在圖像裏面的鏈接,而不是使用鏈接href我想使用img src重定向到圖像路徑。jquery重定向到圖像src或數據attr

與此可能獲得img src但如何使用src重定向?感謝的

$(".drop a").click(function() { 
    alert($(this).children('img').attr('src')); 
}); 

<div class="drop"> 
<a href""><img src=".." /></a> 
</div> 
+0

警報是否給你正確的網址是什麼? – Rajesh

+1

可能的重複[如何重定向到JavaScript/jQuery中的另一個頁面?](http://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-page-in-javascript-jquery ) – Rajesh

+0

@Rajesh是的!給 – japalow

回答

-1

只需使用window.location

代碼: -

$(".drop a").click(function() { 

    window.location = $(this).children('img').attr('src'); 
    return false; 
}); 
+0

雖然你的回答是正確的,但你應該選擇關閉它作爲重複,因爲這是一個非常明顯的重複 – Rajesh

+0

這就是它謝謝@Arshid KV – japalow