Home >Web Front-end >JS Tutorial >jQuery add new element to dynamic list

jQuery add new element to dynamic list

php中世界最好的语言
php中世界最好的语言Original
2018-03-15 13:50:582376browse

This time I will bring you jQueryAdd new elements to the dynamic list, what are the precautions for jQuery to add new elements to the dynamic list, the following is a practical case, let's take a look one time.

Let’s take a look at the renderings first:

The complete implementation code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery列表添加新元素</title>
<script src="jquery-1.7.2.min.js"></script>
</head>
<body>
<h3>li列表:</h3>
<ol>
    <li>jb51</li>
    <li>php</li>
    <li>javascript</li>
    <li>HTML5</li>
</ol>
<input type="text" id="text">
<input type="button" id="btn" value="添加">
<script type="text/javascript">
 $(function () {
    $('#btn').click(function () {
      $('ol').append('<li>'+$('#text').val()+'</li>');
    });
});
</script>
</body>
</html>

I believe you have mastered the method after reading the case in this article. For more exciting content, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Practical jQuery drawer-style online customer service

Detailed instructions for using the image viewing plug-in Magnify

JS to merge the same cells in the table

##How to implement dynamic data paging with jQuery+ajax

The above is the detailed content of jQuery add new element to dynamic list. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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