这个 插入符() 是jQuery中的一个内置方法,用于在指定元素后插入一些HTML内容。HTML内容将在每次出现指定元素后插入。 语法:
null
$(content).insertAfter(target)
这里的“内容”是在指定目标之后插入的HTML内容。 参数: 它接受一个参数“target”,该参数是插入内容的目标。 返回值: 它不返回任何值。
<!DOCTYPE html> < html > < head > < script </ script > < script > $(document).ready(function() { $("div").click(function() { // insertAfter $("< p >You should follow GeeksForGeeks</ p >").insertAfter("p"); }); }); </ script > </ head > < body > < p >To learn jQuery : </ p > < div >Click here to complete</ div > </ body > </ html > |
输出: 在单击div内容之前-
To learn jQuery : Click here to complete
单击div内容后-
To learn jQuery : You should follow GeeksForGeeks Click here to complete
代码#2:
<!DOCTYPE html> < html > < head > < script </ script > < script > $(document).ready(function() { $("div").click(function() { // insertAfter $("< p >You should follow GeeksForGeeks</ p >").insertAfter("p"); }); }); </ script > </ head > < body > < p >To learn jQuery : </ p > < p > To learn coding : </ p > < div >Click here to complete</ div > </ body > </ html > |
输出: 在单击div内容之前-
To learn jQuery : To learn coding : Click here to complete
单击div内容后-
To learn jQuery : You should follow GeeksForGeeks To learn coding : You should follow GeeksForGeeks Click here to complete
jQuery是一个开源JavaScript库,可以简化HTML/CSS文档之间的交互,它以其独特的编程理念而广为人知 “少写多做” . 通过以下步骤,您可以从头开始学习jQuery jQuery教程 和 jQuery示例 .
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END