This article shares the specific code of jQuery to implement a simple comment area for your reference. The specific content is as follows 1. Let’s take a look at the effect first①Click "Publish" ②Click "Delete Comment" 2. How to implementFirst, we use HTML and CSS to write such an area: HTML content: <div id="box"> <div id="fabu"> <textarea placeholder="Please enter the content!!!" id="text"></textarea> </div> <button onclick="fun1()" id="btn_1">Publish</button> <div id="pinlun"> </div> </div> ① Let's first write a big box to wrap all the contents inside ②Write a text, a publish button, and a comment area ③Click the button and the onclick event will execute the function fun1() CSS content: *{ padding: 0; margin: 0; } #box{ width: 600px; background-color: aqua; margin: 0 auto; } #fabu{ width: 600px; height: 300px; background-color: burlywood; } #pinlu{ width: 600px; background-color: aqua; } textarea{ width: 600px; height:300px; border: none; background-color: burlywood; font-size: 24px; } #btn_1{ width: 600px; height: 30px; background-color: cornflowerblue; outline: none; } ::placeholder{ font-size: 24px; } #btn_2{ width: 80px; height: 30px; background-color: brown; border-radius: 4px; } p{text-align: right;} #neirong{ background-color: coral; border: 1px solid burlywood; } ① *{} Let's first set the default inner and outer margins of all elements to 0 ②Then set the corresponding styles for each element accordingly ③Use the ::placeholder pseudo-element tag to set the size of the prompt text ④ We do not set the height of the parent box and the div of the comment area, and let it expand according to the amount of comment content. function fun1(){ $('#pinlun').append( "<div id='neirong'>" + text.value+"<br><p><button id='btn_2'>Delete comment</button></p></div>"); text.value="";} (function fun2() { $("#pinlun").on("click", "button", function() { $(this).parent().parent().remove(); })})() ①jQuery uses $("selector") to get elements ②The append() method adds content (including tags) to the specified element ③When we click to execute fun1(), we also need to set the content to empty ( text.value="") ④Because the pixels that appear when you click are added by the browser later 1. So we cannot find the element if we bind the listener event directly (it will report that the element is undefined) ⑤Because the function is bound to the button, this is the button. To delete, we must delete the content of the div, and parent() is to find the parent element. ⑥The father of button's father is the added div, remove() method: delete the element The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Realization of real-time file synchronization between Linux servers
>>: mysql query data from one table and insert it into another table implementation method
Table of contents Avoid using the spread operator...
This article shares the specific code of js to im...
If you want to hide content from users of phones, ...
Preface Through my previous Tomcat series of arti...
This article uses an example to describe how to q...
This article is welcome to be shared and aggregat...
1. When ffmpeg pushes video files, the encoding f...
Sometimes it is necessary to perform simple verif...
Many people say that IE6 does not support PNG tra...
The image of the microservice will be uploaded to...
Today I found that WordPress could not connect to...
Table of contents mvc mvp mvvm The source of Vue ...
Recently, I plan to deploy a cloud disk on my hom...
The situation is as follows: (PS: The red box repr...
In Google Chrome, after successful login, Google ...