希望这会有所帮助.console.log( $("#2015-11-30\\|1112\\|1").text() );<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id="2015-11-30|1112|1">Div 文本示例</div>syntax error, unrecognised expression: #2015-11-30|1112|1I have an anchor tag with an Id of '2015-11-30|1112|1' that I would like to apply a class to. I am doing the same method for on a '' and this works, but I am getting syntax errors with the following. Can anyone explain the syntax error? $(document).ready(function() { $("#tbl_calendar").on("click", "a", null, clickAppointment); });function clickAppointment(eventData) { //Get the Id of the appointment that has been clicked: currentAppointment = $(this).attr('id'); //alert('clicked' + '#'+currentAppointment) $('#'+currentAppointment).addClass('selected'); } 解决方案 You should escape the special chracters in your id using \\, check example bellow.Hope this helps.console.log( $("#2015-11-30\\|1112\\|1").text() );<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id="2015-11-30|1112|1">Div text example</div> 这篇关于jQuery 语法错误,无法识别的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-25 20:05