积极答复者
关于MSGesture和jquery的一个奇怪的bug

问题
-
代码如下:jquery版本v2.0.3
var item = document.createElement("div"); item.style.width = "200px"; item.style.height = "200px"; item.style.backgroundColor = "red"; gesture = new MSGesture(); gesture.target = item; $("section[role='main']").append(item); //document.querySelector("section[role='main']").appendChild(item); console.log(gesture.target);
如果使用jquery来append,那么console.log 那里,gesture.target就变成null了
而用document.quer...appendChild就没有这个问题,gesture.target的值还是item
这个是什么原因呢
答案
-
Hi KingoWang,
重现了下代码,的确发现有类似的情况发生。
我个人猜想有如下可能性:我们知道JQuery中的Append是复制对象后的添加,而document.appendChild是直接添加,从原理上来说,JQuery的Append方式首先是创建一个临时对象,然后把临时对象复制到目标中,但是JQuery可能不能识别target的函数,导致复制的时候忽略了这个内容,所以当item被Append上去之后这里的内容就变成了null。
以上。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已建议为答案 Jamles HezModerator 2013年10月17日 0:55
- 已标记为答案 Jamles HezModerator 2013年10月29日 5:07
全部回复
-
Hi,Kingo
您是在8.1环境还是8.0环境开发的?
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
Hi KingoWang,
重现了下代码,的确发现有类似的情况发生。
我个人猜想有如下可能性:我们知道JQuery中的Append是复制对象后的添加,而document.appendChild是直接添加,从原理上来说,JQuery的Append方式首先是创建一个临时对象,然后把临时对象复制到目标中,但是JQuery可能不能识别target的函数,导致复制的时候忽略了这个内容,所以当item被Append上去之后这里的内容就变成了null。
以上。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已建议为答案 Jamles HezModerator 2013年10月17日 0:55
- 已标记为答案 Jamles HezModerator 2013年10月29日 5:07