本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
在HTML中,标签的href属性用于指定URL地址。
因为href是一个属性,在jquery中可以利用属性操作方法attr()来改变href的值。
attr() 方法设置或返回被选元素的属性值。
语法:
复制代码1
2
$(selector).attr(attribute,value)
$(selector).attr({attribute:value,....})
登录后复制
示例:
复制代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("a").attr({"href":"https://www.uoften.com/"});
$("link").attr("href","style.css");
});
});
</script>
</head>
<body>
<a href="#">超链接文本</a><br>
<link rel="stylesheet" type="text/css" href="#" />
<br>
<button>修改href属性</button>
</body>
</html>
登录后复制
相关视频教程推荐:jQuery教程(视频)
以上就是jquery怎么改变href的值的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是含蓄红牛最近收集整理的关于jquery怎么改变href的值的全部内容,更多相关jquery怎么改变href内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复