3

Safari에서만 (실제로 MacBook에서 작동하는 경우)이 콘솔 오류가 조금 있습니다. jQuery.Deferred exception : 문자열이 예상 된 패턴과 일치하지 않았습니다.

function exists(element){ 
    var exists = document.querySelector(element); 
    return exists; 
} 

다른 함수 내에서 호출 :

나는이 기능이 크롬 매력처럼 작동에

function includeHoverStylesheet(){ 
    var path = $("body").attr("data-hover"); 
    if (!("ontouchstart" in document.documentElement || exists("link[href='" + path + "'"))) { 
     var link = document.createElement("link"); 
     link.rel = "stylesheet", link.href = path, document.head.appendChild(link) && document.body.removeAttribute("data-hover"); 
    } 
} 

지금,하지만 사파리에 콘솔이 오류 던져 :

1) Invalid CSS property declaration at: * 
2) jQuery.Deferred exception: The string did not match the expected pattern. 
3) SyntaxError (DOM Exception 12): The string did not match the expected pattern. 

누군가 도대체 ​​무슨 일이 일어 났는지 생각나요 ???

미리 감사드립니다.

+1

'()' '개구 가지고 존재로 전달 된 문자열 ['하지만'] '오류를 일으킬 정도이다. –

답변

3

닫는 대괄호가 없어서 잘못된 선택자를 사용하고 있습니다. 모든 jquery-를 들어 https://www.reddit.com/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/

:

다른 브라우저에 잘못된 선택기가 테스트되었습니다 다음의 논의를 살펴 갖는 (주석으로 언급 로머-1888로) 만 사파리는 엄격한 데리고 오류입니다 사용자 : 선택기 문제에 버그 수정이 있었으므로 jquery 버전을 확인하십시오.

내가이 문장에만 사파리 같은 오류 했다

var div = $('<div class="abc">'); 

파이어 폭스와 크롬에서 잘 작동하는 문 있지만 버전 JQuery와 1.11.1을 사용하는 경우 사파리에; 하지만 jquery 1.12.4를 사용하여 모두 잘 작동합니다. 제 경우

난 다음 구문을 사용하여 해결 아니오

var div = $('<div>', {"class":"abc"});