学习代码:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> * { padding: 0; margin: 0; } body{ background-image: url(0.jpg); background-repeat: no-repeat; background-attachment: fixed; background-size: 100% 100%; } div{ width:200px; height: 200px; background-color: orangered; } </style> <script src="jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script> <script> $(function(){ //要求:点击按钮.在div中添加一个超链接,设置超链接的title 属性和热点文字. //地址 $("#btn").click(function(){ var obj=$("<a></a>"); obj.attr("title","创智播客好帅"); obj.attr("href","http://www.itcast.cn"); obj.text("传智播客"); $("#dv").append(obj); console.log(obj.attr("href")); }) }) </script> </head> <body> <h1>在div中设置超链接</h1> <hr > <input type="button" name="" id="btn" value="设置超链接" /> <div id="dv"></div> </body> </html>
Nearth===>WEB前端--第25课/JQuery/如何在div中设置超链接
最新推荐文章于 2022-10-19 17:20:51 发布