您的位置:首页 > Web前端 > JQuery

jQuery禁用a和input 打开链接页面

2010-04-19 13:34 246 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery禁用a和input 打开链接页面</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").attr('href','#');     //修改<a>的 href属性值为 #  这样状态栏不会显示链接地址
$("a").click(function(event){
event.preventDefault();   // 如果<a>定义了 target="_blank“ 需要这句来阻止打开新页面
alert("抱歉!此项目已停用!");
});
$("input").attr('onclick',''); //修改<input>的onclick事件为空
$("input").click(function(){
alert("抱歉!此项目已停用!");
});
});
</script>
</head>

<body>
<a href="http://www.baidu.com" target="_blank">baidu</a>
<a href="http://www.google.cn" target="_blank">google</a>
<input type="button" value="click" onclick="javascript:window.open('http://www.sina.com.cn','_blanks')" />
</body>
</html>


当然,如果整个页面里希望有某一个链接可以打开,如<a href="" id="butme"></a>,可以:

$("a").not("#butme").attr('href','#');

$("a").not("#butme")click(function(){.....});

多个则使用class
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: