html:
<!DOCTYPE ><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <style type="text/css"> * { margin: 20; padding: 0; font-family: "微软雅黑", "arial", " sans-serif"; } #div_id{ background: #76DBA3; } .div_class{ width: 300px; } </style> <script type="text/javascript" src="js/jquery-2.2.2.min.js"></script> <script type="text/javascript"> $(function() { $("#btn_setAttr").click(function() { $("#div").attr({ "id":"div_id", "class":"div_class" }); }); }) </script> </head> <body> <div id="div" class="div2" style="height: 200px;border: 1px red solid;"> </div> <input id="btn_setAttr" type="button" value="设置属性信息" /> </body> </html>
result:
时间: 2024-10-08 11:13:32