ID结束在纯JavaScript [英] ID Ends With in pure Javascript

查看:103
本文介绍了ID结束在纯JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Javascript库工作,引入jQuery一件事:一个结束于选择器。它看起来像这样:

I am working in a Javascript library that brings in jQuery for one thing: an "ends with" selector. It looks like this:

$('[id$=foo]')

它会找到 id 以foo结尾的元素。

It will find the elements in which the id ends with "foo".

我希望没有jQuery(直的JavaScript)。你怎么可能这样?

I am looking to do this without jQuery (straight JavaScript). How might you go about this? I'd also like it to be as efficient as reasonably possible.

推荐答案

使用 querySelectorAll 不适用于所有浏览器(如IE 5/6/7/8)。它基本上类似于jQuery:

Use querySelectorAll, not available in all browsers (like IE 5/6/7/8) though. It basically works like jQuery:

http://jsfiddle.net/BBaFa/ 2 /

console.log(document.querySelectorAll("[id$=foo]"));

这篇关于ID结束在纯JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆