Angularjs jqlite追加()和jQuery的append()以&lt采取不同; TD> [英] Angularjs jqlite append() and jquery append() act differently with <td>

查看:509
本文介绍了Angularjs jqlite追加()和jQuery的append()以&lt采取不同; TD>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一些元素来一个,我用的时候看到一些不同的行为内置jqlite VS使用jQuery。我创建了一个小提琴证明的区别: http://jsfiddle.net/waylon999/5fyBt/1/

I'm trying to append some elements to a and I'm seeing some different behavior when using the built-in jqlite vs using jquery. I created a fiddle to demonstrate the difference: http://jsfiddle.net/waylon999/5fyBt/1/

看来,当我做的:

element.append('<td>Val 1</td><td>Val 2</td>'); // jqlite

插入字符串之前的

标签被剥离。但是,当我尝试

the tags are stripped before the string is inserted. But when I try

$(element).append('<td>Val 1</td><td>Val 2</td>'); 

它的工作,因为我所期望的,其中追加整个字符串ARG追加到标签。我试了几件事情,包括

It works as I would expect, where the entire string arg in append is appended to the tag. I tried a couple of things including

angular.element(element).append(....)

但我不能找到一种方法,使其工作。有什么事我不理解如何这应该工作?

but I can't find a way to make it work. Is there something I'm not understanding about how this should work?

谢谢!

推荐答案

作为最好的,我可以告诉,这是一个错误的JQLite:

As best I can tell, it's a bug in JQLite:

function JQLite(element) {

    ...

    if (isString(element)) {
        var div = document.createElement('div');
        // Read about the NoScope elements here:
        // http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
        div.innerHTML = '<div>&#160;</div>' + element; // IE insanity to make NoScope elements work!
        div.removeChild(div.firstChild); // remove the superfluous div
        JQLiteAddNodes(this, div.childNodes);
        this.remove(); // detach the elements from the temporary DOM div.
    } else {
        JQLiteAddNodes(this, element);
    }
}

正如您可能会或可能不知道,你不能做到这一点:

As you may or may not know, you cannot do this:

div.innerHTML = '<div></div><td>asdf</td>';

D 将被删除。我猜的jQuery不会做同样的事(或许他们不关心了noscope?)。也就是说,如果你想继续只使用角度,这工作得很好:

The td will be removed. I'm guessing jQuery doesn't do the same thing (perhaps they're not concerned with NoScope?). That said, if you want to continue to just use Angular, this works just fine:

element[0].innerHTML += '<td>Val 1xx</td><td>Val 2yy</td>'; 

我建议对角的github上提出的问题。

I recommend filing an issue on Angular's github.

这篇关于Angularjs jqlite追加()和jQuery的append()以&lt采取不同; TD&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆