Home > Web Front-end > JS Tutorial > jquery prepend函数实例

jquery prepend函数实例

WBOY
Release: 2016-06-01 09:54:57
Original
1217 people have browsed it

首先介绍一下prepend函数的语法:

语法

<code class="language-javascript">$(selector).prepend(content)</code>
Copy after login

其中,content 必需。规定要插入的内容(可包含 HTML 标签)。

实例:

<code class="language-html">

<script type="text/javascript" src="http://www.manongjc.com/Public/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#manong").click(function(){
        $("#content").prepend('码农教程');
        });
    });
</script>


<div id="content" style="border:1px #ccc solid">这是原来内容。</div>
<button id="manong">插入文本</button>

</code>
Copy after login

在线运行

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template