小白教程
所有教程
关于
Search
172.71.254.7
172.71.254.7
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Html prepend”的源代码
本页内容
上一节:
Css_position
下一节:
Html_prependto
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:prepend()}}[[Category:jquery ref html|23]] = jQuery prepend() 方法 = [[jquery ref html|jQuery HTML/CSS 方法]] 在所有 <p> 元素开头插入内容: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ $("p").prepend("<b>Prepended text</b>"); }); </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(){ $("#btn1").click(function(){ $("p").prepend("<b>在开头追加文本</b>。 "); }); $("#btn2").click(function(){ $("ol").prepend("<li>在开头添加列表项</li>"); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另外一个段落。</p> <ol> <li>列表 1</li> <li>列表 2</li> <li>列表 3</li> </ol> <button id="btn1">添加文本</button> <button id="btn2">添加列表项</button> </body> </html> </run> == 定义和用法 == prepend() 方法在被选元素的开头插入指定内容。 '''提示:'''如需在被选元素的结尾插入内容,请使用 [[html append|append()]] 方法。 == 语法 == <pre> $(selector).prepend(content,function(index,html))</pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | content | 必需。规定要插入的内容(可包含 HTML 标签)。 可能的值: * HTML 元素 * jQuery 对象 * DOM 元素 |- | function(index,html) | 可选。规定返回待插入内容的函数。 * index - 返回集合中元素的 index 位置。 * html - 返回被选元素的当前 HTML。 |} == 更多实例 == [[try.php?filename=tryjquery_html_prepend_ref|prepend() - 通过 HTML、jQuery 和 DOM 创建内容]] 通过 prepend() 方法插入内容。 [[try.php?filename=tryjquery_html_prepend_func|使用函数预加内容]] 使用函数在被选元素的开头插入内容。 [[jquery ref html|jQuery HTML/CSS 方法]]
返回至“
Html prepend
”。
上一节:
Css_position
下一节:
Html_prependto