2014-10-28 2 views
3

이 문제를 해결할 수없는 것 같습니다.Jquery 이스케이프 선택기 인식 할 수없는 식 : [data-route = search \/child]

SPA 앱에서 다른 경로가 있습니다. #/search #/other #/search/child. 해시 태그를 구문 분석하고 속성 데이터 경로가 포함 된 요소를 표시하거나 숨 깁니다.

경로가 한 부분으로 구성되면 #/모든 것이 잘 동작합니다. Jquery가 $ ('[data-route = search]')를 수행하고 있습니다. 나는 두 번째 부분 번호/검색/자녀를 추가 할 때

, 나는 "\/아이 검색"으로 선택을 탈출하지만, jQuery를 다음과 같은 오류 MSG와 선택 실행하는 데 실패

Uncaught Error: Syntax error, unrecognized expression: [data-route=search\\/child] jquery.js:1850Sizzle.error jquery.js:1850tokenize jquery.js:2460select jquery.js:2847Sizzle jquery.js:1289jQuery.fn.extend.find jquery.js:5730jQuery.fn.jQuery.init jquery.js:197jQuery jquery.js:63allroutes MainView.js:21apply director.js:511_every director.js:308Router.invoke director.js:516updateAndInvoke director.js:474Router.dispatch director.js:482handler director.js:203onchange director.js:76 

내가 열 경우를 콘솔과 동일한 선택기를 실행, 그것은 잘 작동합니다.

var route = window.location.hash.slice(2); 
route = route.replace('/','\\\\/'); 
var sections = $('[data-route]'); 
var selector = "[data-route=" + route + "]"; 
var section = $(selector); 

if (section.length) { 
    sections.hide(250); 
    section.show(250); 
} 
+0

'[data-route = "search/child"]','[data-route = "search \/child"]','[data-route = "search \\/child"]' . – amphetamachine

답변

4

인용 부호를 사용해보십시오.

var selector = "[data-route=\"" + route + "\"]"; 

도대체 /을 탈출 할 필요가 없습니다.

+0

그게 효과가! 감사! – sesteva

관련 문제