如何在正文中制作标签以正确显示

How do I make a tag in the body to properly show

本文关键字:标签 显示 正文      更新时间:2023-09-26
xml = '<?xml version="1.0" encoding="utf-8"?><root><html><a href="#">the new link</a></html></root>';

这些变量是我的

 $(function(){
xml = '<?xml version="1.0" encoding="utf-8"?><root><html><a href="#">the new link</a></html></root>';
$xmls =$($.parseXML( xml ));
$('button').on('click',function(){
    console.log($xmls.find('html > *')[0]);
    $('body').append($xmls.find('html > *')[0]);
});
})

添加的 A 标记不起作用

pre 标签将显示为 A 标签

http://jsfiddle.net/GgXEp/1/

演示

我修好了。它适用于每个浏览器。我花了一些时间,所以我希望它能奏效。我还在 xml 文档中添加了另一个链接,使其可见它只选择索引为 0 的元素:

$('button').on('click',function(){
    HTML = $($.parseHTML(xmls.find('root').text()));
    console.log(HTML[0]);
    $('body').append(HTML[0]);
});

经过 1 个小时的处理和思考,我会为您提供一个解决方法:

首先,将jquery库更新为1.9.1(可能是1.10.1的问题,因为控制台在IE和Opera中给了我访问被拒绝),然后让我们将找到的元素存储在jquery变量中,如下所示:

$element = xmls.find('html > *').first();

然后让我们使用 jquery 创建一个锚点:

$a = $("<a>").attr( "href", $element.attr("href") ).text( $element.text() );

之后,让我们在单击操作时添加按钮:

$('button').on('click', function () {
   $('body').append($a);
});

当然,证据:Jsfiddle