Tra*_*er1 18
现代浏览器:(IE9 +)
//slice turns the resulting DOM collection into a proper array
var matches = [].slice.call(document.querySelectorAll('[id^=log_]'));Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('[id^=log_]')
Run Code Online (Sandbox Code Playgroud)
旧浏览器,没有jQuery:
var matches = [];
var elems = document.getElementsByTagName("*");
for (var i=0; i<elems.length; i++) {
if (elems[i].id.indexOf("log_") == 0)
matches.push(elems[i]);
}
//matches now is an array of all matching elements.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15393 次 |
| 最近记录: |