App下載

JavaScript如何實(shí)現(xiàn)頁(yè)面中跳轉(zhuǎn)??jī)煞N方法介紹

猿友 2021-05-31 17:21:11 瀏覽數(shù) (2498)
反饋

網(wǎng)頁(yè)開發(fā)中,經(jīng)常會(huì)涉及到網(wǎng)頁(yè)間的跳轉(zhuǎn)。那么這篇文章中,w3cschool 小編來為大家介紹一下 JavaScript 如何實(shí)現(xiàn)頁(yè)面中的跳轉(zhuǎn)。

方法一:

<body>
	<input type="button" value="點(diǎn)擊跳轉(zhuǎn)" onclick="tran()">
	<script type="text/javascript">
	    function tran(){
		window.open("http://www.o2fo.com/");}
	</script>
</body>

上述代碼中,點(diǎn)擊按鈕時(shí)會(huì)觸發(fā)響應(yīng),將會(huì)打開新窗口,并跳轉(zhuǎn)頁(yè)面。

方法二:

<body>
	<input type="button" value="點(diǎn)擊跳轉(zhuǎn)" onclick="tran()">
	<script type="text/javascript">
	    function tran(){
		window.location.href="http://www.o2fo.com/";}
	</script>
</body>

該方法中,也會(huì)跳轉(zhuǎn)為新頁(yè)面,但不會(huì)產(chǎn)生新的窗口,而是在舊窗口中跳轉(zhuǎn)為新頁(yè)面。

以上就是文章“JavaScript 如何設(shè)置打開新窗口??jī)煞N方法介紹”的全部?jī)?nèi)容。更多 JavaScript 學(xué)習(xí)請(qǐng)前往 w3cschool。

0 人點(diǎn)贊