在页面中放置两个段落P标记,并在该标记内分别设置两个span标记,通过wrap和wrapInner()两种方法,改变标记中的外部元素与内部文本的字体显示方式。
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>包裹元素节点title> <script type="text/javascript" src="../jquery-2.1.4.js">script> <style type="text/css"> body{ font-size:13px;} p{ background-color:#eee; padding:5px; width:200px} style> <script type="text/javascript"> $(function(){ $("P").wrap(""); $("span").wrap(""); }) script> head> <body> <p>最喜爱的体育运动:<span>羽毛球span>p> <p>最爱看哪类型图书:<span>网络、技术span>p> body> html>