查找以id开头的html元素
问题描述:
我的问题是这个
我在多个页面中都有HTML代码,在每个页面上我都使用JQgrid(jQuery网格)来显示一些数据.我知道在每个页面上,保存JQgrid的元素都被命名为"LIST_xxx".现在,我需要制作一个JavaScript,在每个页面上使用该元素"LIST_XXXX"并执行一些操作.我如何才能通过ID搜索元素,但仅知道其初始部分(如我之前提到的那样):
I have HTML code in multiple pages, on each of them I used a JQgrid (jquery grid) for display some data. I knew that on each of those pages, the element that holds the JQgrid is named as "LIST_xxx". Now I need to make a javascript that takes that element "LIST_XXXX" on each page and does some stuff. How could I search for an element by ID but only knowing its initial part (of the ID ,like i mentioned previously):
$('#list_[XXXX]')... --> The part surrounded by [] is variable on each page, i want to discriminate that.
我希望我能说清楚.谢谢.
I hope i made myself clear. Thanks.
答
尝试
$('div[id^="list_"]')
应该可以