Tôi có HTML với một số thẻ tùy chỉnh. Tôi muốn tìm tất cả trừ hai ('bắt đầu', 'kết thúc') và bỏ chúng ra. jQuery.find() dường như chỉ tìm thấy các thẻ tùy chỉnh này khi tôi tìm kiếm những gì trong tài liệu, chứ không phải khi tôi tìm kiếm một đối tượng jQuery. Tôi đang làm gì sai?jQuery sẽ không tìm thấy thẻ tùy chỉnh
có nên tự giải thích trong fiddle:
Đây là một phần 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)
và một ví dụ về 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>
mà nên là:
CTAGCTCTCTGGAGATTAACGAGGAGAAATACTAGAtTGGTTCAT<start feat="1" class="ng-scope"></start>GATCATAAgcttgaat<end feat="1" class="ng-scope"></end>tagccaaacttatt
Cảm ơn
html với các thẻ tùy chỉnh không còn html –
với ngoại lệ của
Tại sao viết HTML theo cách này? Các lợi ích nào gắn thẻ ' ' có hơn '
' hoặc ''? Chưa kể, sử dụng bộ chọn '$ ('. ClassName')' nhanh hơn '. – Dom