jQuery.htmlPrefilter( html )
jQuery.htmlPrefilter( html )
설명 : jQuery 조작 메소드를 통해 전달 된 HTML 문자열을 수정하고 필터링 합니다 .
이 방법은 거의 직접 호출 할 필요가 없습니다. 대신 엔트리 포인트로 사용하여 기존 jQuery 조작 메소드 를 수정하십시오 . 예를 들어 <del>들어오는 HTML 문자열에서 모든 태그 를 제거하려면 다음을 수행하십시오.
var htmlPrefilter = $.htmlPrefilter,
rdel = /<(del)(?=[\s>])[\w\W]*?<\/\1\s*>/gi;
$.htmlPrefilter = function( html ) {
return htmlPrefilter.call( this, html ).replace( rdel, "" );
};
이 기능은 특정 엣지 케이스 문제를 우회하기 위해 덮어 쓸 수도 있습니다. htmlPrefilterjQuery 의 기본 기능은 모든 태그가 XHTML과 호환되는지 확인합니다. 여기에는 HTML 태그처럼 보이지만 실제로는 문자열 내에있는 모든 것이 포함됩니다 (예 :
<a title="<div /> "> <>
). jQuery.htmlPrefilter()기능은 이것을 무시하기 위해 사용될 수있다 :
$.htmlPrefilter = function( html ) {
// Return HTML strings unchanged
return html;
};
그러나 위의 해결 방법은 짧고 간단하지만 모든 HTML 문자열에서 XHTML 호환 태그를 보장해야하는 부담이 있습니다. 이 문제에 대한보다 철저한 수정은 다음과 같습니다.
var panything = "[\\w\\W]*?",
// Whitespace
// https://html.spec.whatwg.org/multipage/infrastructure.html#space-character
pspace = "[\\x20\\t\\r\\n\\f]",
// End of tag name (whitespace or greater-than)
pnameEnd = pspace.replace( "]", ">]" ),
// Tag name (a leading letter, then almost anything)
// https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state
// https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state
pname = "[a-z]" + pnameEnd.replace( "[", "[^/\\0" ) + "*",
// Void element (end tag prohibited)
// https://html.spec.whatwg.org/multipage/syntax.html#void-elements
pvoidName = "(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|" +
"source|track|wbr)(?=" + pnameEnd + ")",
// Attributes (double-quoted value, single-quoted value, unquoted value, or no value)
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
pattrs = "(?:" + pspace + "+[^\\0-\\x20\\x7f-\\x9f=\"'/>]+(?:" + pspace + "*=" + pspace +
"*(?:\"" + panything + "\"|'" + panything + "'|" +
pnameEnd.replace( "[", "[^" ) + "*(?!/)" +
")|))*" + pspace + "*",
// Trailing content of a close tag
pcloseTail = "(?:" + pspace + panything + "|)",
rspecialHtml = new RegExp(
// Non-void element that self-closes: $1–$5
"(<)(?!" + pvoidName + ")(" + pname + ")(" + pattrs + ")(\\/)(>)|" +
// No-innerHTML container (element, comment, or CDATA): $6
"(<(script|style|textarea)" + pattrs + ">" + panything + "<\\/\\7" + pcloseTail + ">|" +
"<!--" + panything + "--)",
"gi"
),
// "<"; element name; attributes; ">"; "<"; "/"; element name; ">"; no-innerHTML container
pspecialReplacement = "$1$2$3$5$1$4$2$5$6";
$.htmlPrefilter = function( html ) {
return ( html + "" ).replace( rspecialHtml, pspecialReplacement );
};
댓글 1개
그누보드에 이런게시판도 있엇네요 자주 올께용
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4796 | jQuery | 8년 전 | 1534 | ||
| 4795 | jQuery | 8년 전 | 1438 | ||
| 4794 | jQuery | 8년 전 | 1563 | ||
| 4793 | jQuery | 8년 전 | 1620 | ||
| 4792 | jQuery | 8년 전 | 1628 | ||
| 4791 | jQuery | 8년 전 | 1794 | ||
| 4790 | jQuery | 8년 전 | 1735 | ||
| 4789 | jQuery | 8년 전 | 1599 | ||
| 4788 | jQuery | 8년 전 | 1660 | ||
| 4787 | jQuery | 8년 전 | 1475 | ||
| 4786 | jQuery | 8년 전 | 1434 | ||
| 4785 | jQuery | 8년 전 | 1645 | ||
| 4784 | jQuery | 8년 전 | 1524 | ||
| 4783 | jQuery | 8년 전 | 1232 | ||
| 4782 | jQuery | 8년 전 | 1600 | ||
| 4781 | jQuery | 8년 전 | 1339 | ||
| 4780 | jQuery | 8년 전 | 1575 | ||
| 4779 | jQuery | 8년 전 | 1983 | ||
| 4778 | jQuery | 8년 전 | 1958 | ||
| 4777 | jQuery | 8년 전 | 1529 | ||
| 4776 | jQuery | 8년 전 | 1582 | ||
| 4775 | jQuery | 8년 전 | 1971 | ||
| 4774 | jQuery | 8년 전 | 1486 | ||
| 4773 | jQuery | 8년 전 | 1410 | ||
| 4772 | jQuery | 8년 전 | 2203 | ||
| 4771 | jQuery | 8년 전 | 3611 | ||
| 4770 | PHP | 8년 전 | 5579 | ||
| 4769 | 기타 | 8년 전 | 1964 | ||
| 4768 | 기타 | 8년 전 | 1781 | ||
| 4767 | 기타 | 8년 전 | 2067 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기