jquery 'attribute contains' selector with a dynamic value

前端 未结 2 1690
孤街浪徒
孤街浪徒 2021-01-18 03:41

Let\'s say that i have a variable questionId which is an integer, and i want to find tr elements that have the fragment (\"question_\"+questi

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 04:09

    You have error:

    var questionId = 7674;
    $("tr[id*='quiz_question_" + questionId + "']");
    

    Notes:

    1. Please use var to declare variables.
    2. questionId is a variable. It is not part of the selector. You should concatenate questionId to the string.

提交回复
热议问题