jQuery: unrecognized expression

后端 未结 2 1513
忘掉有多难
忘掉有多难 2021-01-18 02:19
$(document).ready(function(){

    var page = window.location.hash;
    if(page != \"\"){
        $(\'a[href=\'+ page +\']\').addclass(\'selected\');
        pageloa         


        
相关标签:
2条回答
  • 2021-01-18 02:44

    Your regular expression doesn't need the speech marks:

    replace(#/page/, ...
    
    0 讨论(0)
  • 2021-01-18 02:57

    Try this instead:

    $('a[href="'+ page +'"]').addClass('selected');
    

    (You need to escape the value of the href – with this, you get a[href="#/page/link"].)

    0 讨论(0)
提交回复
热议问题