Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery赢得';找不到自定义标记_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery赢得';找不到自定义标记

Javascript jQuery赢得';找不到自定义标记,javascript,jquery,html,Javascript,Jquery,Html,我有几个自定义标记的HTML。我想找到除了两个(“开始”、“结束”)之外的所有东西,然后打开它们。find()似乎只有在搜索文档中的内容时才能找到这些自定义标记,而不是在搜索jQuery对象时。我做错了什么 在小提琴中应该不言自明: 下面是javascript部分: var raw = $('pre').html(); var html = $(raw); var starts = html.find('start'); var spans = html.find('span'); //th

我有几个自定义标记的HTML。我想找到除了两个(“开始”、“结束”)之外的所有东西,然后打开它们。find()似乎只有在搜索文档中的内容时才能找到这些自定义标记,而不是在搜索jQuery对象时。我做错了什么

在小提琴中应该不言自明:

下面是javascript部分:

var raw = $('pre').html();
var html = $(raw);
var starts = html.find('start');
var spans = html.find('span');

//this returns nothing
console.log(starts)
// works - can find in object
console.log(spans)
//this works
console.log($('start'));


//only picks up spans, not annotations
// I want this to return the innerHTML of the pre, stripping all tags except for 'start' and 'end' -- but retain the contents of those tags.
var cleaned = html.find(':not(start, end)').each(function() {
    $(this).contents().unwrap();
});

console.log(cleaned);

$('#clean').html(cleaned)
还有一个HTML示例:

<span class="ng-scope">CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT</span>
<start feat="1" class="ng-scope"></start>
<annotation index="1" class="ng-isolate-scope ng-scope" style="background-color: rgb(238, 153, 238); background-position: initial initial; background-repeat: initial initial;">
    <span tooltip="Another Promoter" tooltip-placement="mouse" tooltip-append-to-body="true" ng-transclude="" class="ng-scope">
        <span class="ng-scope">GATCATAAgcttgaat</span>
    </span>
</annotation>
<end feat="1" class="ng-scope"></end>
<span class="ng-scope">tagccaaacttatt</span>
CTAGCTCTCTCTGTGAGAGAGATAACGAGAGAATATCTAGATTGGTTCAT
GATTGAAT
Tagcaacttatt
应该是:

CTAGCTCTCTCTCTCTCTCTGCTGGAGAGATAACGAGAGAGAGAATATCTAGATTGGTTCAGATAGTTGAATAGCAAAACTATT


谢谢,您的问题在于初始变量:

var raw = $('pre').html();
var html = $(raw);
这将转换为
var html=$($('pre').html())
,它将不匹配任何元素。原因是,由于选择器前面没有
#
,因此它实际上是在查找标记:

<start feat="11" class="ng-scope">
</start>
<annotation index="11" class="ng-isolate-scope ng-scope" style="background-color: rgb(238, 204, 153); background-position: initial initial; background-repeat: initial initial;">
</annotaion>
演示:

带有自定义标记的html不再是html,只是为什么要以这种方式编写html?标签
有什么好处?更不用说,使用选择器
$('.className')
.ok会更快-但这仅在它们位于DOM中时才将其展开。我不想直接操作DOM——我想创建一个对象(不绑定到文档)并在那里进行转换。
var html = $('pre');