当前位置:首页>开发>正文

关于jquery中append函数~~ 请教jquery里的append方法

2023-05-23 12:50:56 互联网 未知 开发

 关于jquery中append函数~~ 请教jquery里的append方法

关于jquery中append函数~~

jQuery 1.4 新增的。
这个操作与对指定的元素执行appendChild方法,将它们添加到文档中的情况类似。
function(index, html)
返回一个HTML字符串,用于追加到每一个匹配元素的里边。接受两个参数,index参数为对象在这个集合中的索引值,html参数为这个对象原先的html值。
----------------------------------------------------------------------
所以:
$("p").append(function(m,n){
return "This p element has index " (m n) ""
}
会得到:
This is a paragraph.This p element has index 0This is a paragraph.
This is another paragraph.This p element has index 1This is another paragraph.

也就是原有

中的内容 This p element has index 当前这个p的索引 p自身的内容

请教jquery里的append方法

将div id=child 的 添加到 div id=father 的容器里面去。

1. $("#father").append($("#child"))

2. $("#child").appendTo($("#father"))

jquery 怎么获取append的元素


$(#one).append("test1

")
append后结果:
$(#one).append("test1

")

$("body").on("click","#two",function(data){
    alert(data)
})

Jquery append 方法的疑惑

代码有错误,在append()中写的时候要注意几点:

1、每一行一定要是个完整的字符串。必须都在双引号里边。比如字符串"abcdef",如果要分两行写,必须这样:
“abc”
"def"
即使你整体是在双引号中。我看你的这个就是这个问题。
2、中间如果有正则表达式,特殊字符包括必须前边加,用来转义。

最新文章