2012-07-17 32 views
-2

我發現下面的代碼 做工精良的jQuery:鏈路開放

我想知道如何做到這一點

打開鏈接https://stackoverflow.com/questions/ask?title=jqueryhttp://stackoverflow.com

點擊時這可能嗎? 新的jQuery

<!DOCTYPE html> 
<html> 
<!-- 

    Created using/
    Source can be edited via /uwogi4/2/edit 

--> 
<head> 
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<meta charset=utf-8 /> 
<title>Test Page</title> 
<!--[if IE]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-    -> 
<style> 
    article, aside, figure, footer, header, hgroup, 
    menu, nav, section { display: block; } 
    body { 
    font-family: sans-serif; 
    } 
    p { 
    margin: 0px; 
    } 
</style> 
</head> 
<body> 
    <div>Foo <span class='pc_more'>http://www.google.com</span></div> 
    <div>Bar <span class='pc_more'>http://webvikas.net.in</span></div> 
<script> 
jQuery(function($) { 

    $('div').click(function() { 
    window.location = $(this).find('.pc_more').html(); 
    }); 

}); 
</script> 
<script src="/js/render/edit.js"></script> 
<script>var _gaq=[['_setAccount','UA-1656750-13'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)})(document,'script')</script></body> 
</html> 
+2

有什麼不對的好老''標籤? – JJJ 2012-07-17 07:27:47

回答

2

保持簡單:

$('.pc_more').click(function() { 
    window.location = $(this).html(); 
}); 

你爲什麼要這麼做?像這樣做鏈接和重定向只是錯誤的。 a-tags是由於某種原因發明的......這一個。

你可以簡單地做:

<a href="http://stackoverflow.com/questions/ask?title=jquery" target="_blank">http://stackoverflow.com</a>