jQuery 语法错误,无法识别的表达式

编程入门 行业动态 更新时间:2024-10-27 06:26:41
本文介绍了jQuery 语法错误,无法识别的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

语法错误,无法识别的表达式:#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/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/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="2015-11-30|1112|1">Div text example</div>

这篇关于jQuery 语法错误,无法识别的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 08:27:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1039162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   语法错误   无法识别   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!