jquery after
jQuery after method can be used to add HTML content, DOM element, or jQuery object to insert after each element in the set of matched elements. We can also have function in jQuery after method that returns content to add after the set of matched elements.
jQuery after方法可用于添加HTML内容,DOM元素或jQuery对象,以在匹配的元素集中的每个元素之后插入。 我们还可以在jQuery中的after方法中提供函数,该方法返回要在匹配的元素集之后添加的内容。
jQuery之后 (jQuery after)
jQuery after method is same as insertAfter()
and the difference is in the syntax with the placement of target element and content to add.
jQuery after方法与insertAfter()
相同,不同之处在于语法上带有目标元素和要添加的内容的位置。
Here is an example page where I am dynamically adding new paragraph and text box in HTML page using jQuery.
这是一个示例页面,其中我使用jQuery在HTML页面中动态添加新的段落和文本框。
<html>
<head>
<title>jQuery after() Examples</title>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script>
function addNewParagraph(){
$("p:first").after("<p background-color=red>Dynamic Paragraph</p>");
}
function addNewTextbox(){
$("input:text:last").after("<br><input type='text' name='text2'>");
}
</script>
</head>
<body>
<p>First Paragraph</p>
<input type="button" onclick="addNewParagraph()" value="Add Paragraph">
<br><br>
<input type="text" name="text1">
<br>
<input type="button" onclick="addNewTextbox()" value="Add Textbox">
</body>
</html>
之后的jQuery –自己尝试 (jQuery after – Try it Yourself)
jquery after