jquery preventDefault()方法 語法
jquery preventDefault()方法 語法
作用:preventDefault() 方法阻止元素髮生預設的行為(例如,當點選提交按鈕時阻止對錶單的提交)。
語法:event.preventDefault()
引數:
引數 | 描述 |
event | 必需。規定阻止哪個事件的預設動作。這個 event 引數來自事件繫結函式。 |
jquery preventDefault()方法 示例
<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(event){
event.preventDefault();
});
});
</script>
</head>
<body>
<a href="http://www.furuihua.cn/">大理石平臺</a>
<p>preventDefault() 方法將防止上面的連結開啟 URL。</p>
</body>
</html>