小白教程
所有教程
关于
Search
172.70.130.168
172.70.130.168
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Html replacewith”的源代码
本页内容
上一节:
Html_replaceall
下一节:
Css_scrollleft
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:replaceWith()}}[[Category:jquery ref html|31]] = jQuery replaceWith() 方法 = [[jquery ref html|jQuery HTML/CSS 方法]] 把第一个 <p> 元素替换为新的文本: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ $("p:first").replaceWith("Hello world!"); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p:first").replaceWith("Hello world!"); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另一个段落。</p> <button>使用新文本替换第一个P元素</button> </body> </html> </run> == 定义和用法 == replaceWith() 方法把被选元素替换为新的内容。 == 语法 == <pre> $(selector).replaceWith(content,function(index))</pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | content | 必需。规定要插入的内容(可包含 HTML 标签)。 可能的值: * HTML 元素 * jQuery 对象 * DOM 元素 |- | function(index) | 可选。规定返回替换内容的函数。 * index - 返回集合中元素的 index 位置。 |} == 更多实例 == [[try.php?filename=tryjquery_html_replacewith_element|使用函数替换内容]] 如何使用函数替换把被选元素替换为新的内容。 [[jquery ref html|jQuery HTML/CSS 方法]]
返回至“
Html replacewith
”。
上一节:
Html_replaceall
下一节:
Css_scrollleft