jquery dynamic id

后端 未结 4 1173
广开言路
广开言路 2021-01-06 08:56

i use such code to access item

function f(id){

$(\"#\"+id).val(); // with analogy $(\"#id item\")
}

is it correct? is any other methods?<

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 09:38

    From the jQuery API website:

    .val() Returns: String, Array

    Description: Get the current value of the first element in the set of matched elements.

    What It's not clear to me when you say

    // with analogy $("#id item")

    is if you want to have ONLY one child item of the one that is identifiedby #id or if you need the item that is identified by item#id.

    Your code is perfect if you are passing a string like "hello" inside your code and you want to get the DOM element with ID of #hello.

提交回复
热议问题