jQuery中replaceAll()方法用法实例
本文实例讲述了jQuery中replaceAll()方法用法。分享给大家供大家参考。具体分析如下:
此方法用匹配元素去替换指定的内容。
replaceAll()方法的作用和replaceWith()方法是完全一样的。
语法结构:
$(content).replaceAll(selector)
参数列表:
实例实例:
<!DOCTYPEhtml> <html> <head> <metacharset="utf-8"> <metaname="author"content="https://www.nhooo.com/"/> <title>毛票票</title> <styletype="text/css"> div{ width:100px; height:100px; border:1pxsolidblue; } p{ width:150px; height:150px; border:1pxsolidred; } </style> <scriptsrc="jquery/1.9.0/jquery.js"></script> <scripttype="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("<div>这是div元素</div>").replaceAll("p"); }); }); </script> </head> <body> <p>这是p元素</p> <p>这是p元素</p> <p>这是p元素</p> <button>用div包裹每个段落</button> </body> </html>
希望本文所述对大家的jQuery程序设计有所帮助。