<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jquery 事件</title> <script src='jquery-3.3.1.min.js'></script> <style> #out{ width:300px; height:300px; background: blue; border-radius: 50%; position:absolute; } #mid{ width:200px; height:200px; background: yellow; border-radius: 50%; position: absolute; left:50px; top:50px; } #inr{ width:100px; height:100px; background: purple; border-radius: 50%; position: absolute; left:50px; top:50px; } </style> </head> <body style='height:2000px;width:2000px'> <a href="http://www.baidu.com" id='as'>點(diǎn)擊百度</a> <div id='out'> <div id='mid'> <div id='inr'></div> </div> </div> </body> <script type="text/javascript"> $('#as').click(function(){ //jquery中使用location格式 //location.href = '' location.href = 'http://www,baidu.com'; //replace //replace() 方法用于在字符串中用一些字符替換另一些字符,或替換一個(gè)與正則表達(dá)式匹配的子串。 //此處用于替換掉replace location.replace('http://www.sina.com.cn'); //return false用于阻止默認(rèn)行為 //如果會(huì)產(chǎn)生事件蔓延或事件冒泡,使用return可以組織該事件冒泡或事件蔓延 return false; //事件冒泡/蔓延,是指設(shè)置了一個(gè)總體集合給定了某些樣式,而子元素的樣式也被影響 //使用return false 的方式,可以有效的阻止時(shí)間冒泡; $('div').click(function(){ $(this).css('background','pink'); return false; }) }) </script> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)