jQuery获得内容和属性

jquery通过id和attr方法获取a标签的href属性的地址,并实现跳转:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    window.open($("#baidu").attr("href"),'_self');
  });
});
</script>
</head>

<body>
<p><a href="http://www.baidu.com" id="baidu">百度</a></p>
<button>跳转到百度</button>
</body>
</html>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41153943/article/details/104784086