jQuery 语法错误,无法识别的表达式 [英] jQuery syntax error, unrecognised expression

查看:36
本文介绍了jQuery 语法错误,无法识别的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

语法错误,无法识别的表达式:#2015-11-30|1112|1

我有一个 ID 为2015-11-30|1112|1"的锚标记,我想对其应用一个类.我正在对 '' 执行相同的方法,并且此方法有效,但是出现以下语法错误.谁能解释一下语法错误?

 $(document).ready(function() {$("#tbl_calendar").on("click", "a", null, clickAppointment);});函数 clickAppointment(eventData){//获取被点击的约会的Id:currentAppointment = $(this).attr('id');//警报('点击'+'#'+当前约会)$('#'+currentAppointment).addClass('selected');}

解决方案

您应该使用 \\id 中的特殊字符进行转义,请查看下面的示例.

希望这会有所帮助.

<小时>

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|1

I 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 语法错误,无法识别的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆