选择具有特定属性的元素 [英] select element which have specific attribute

查看:78
本文介绍了选择具有特定属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有没有任何类或ID的输入按钮,并且在onclick attr上是这样的:

I've the input buttons without any class or id and have onclick attr on that something like this:

<input type="button" onclick="myfunc();" />

还有其他输入类型的按钮,并且希望对具有onclick属性的按钮进行样式设置.

And there are other input type buttons too and want to style to the buttons which have onclick attribute.

所以,在这里我可以这样:

So, here I can do like this:

input[onclick="myfunc();"]{color: red;}

但是在onclick中可能有任何函数,例如myfunc(),thisfunc()或anyfunc().

But in the onclick there may be any function like myfunc(), thisfunc(), or anyfunc().

那么我该如何选择具有onclick属性的那些输入按钮.

So how can I select those input buttons which have onclick attribute.

推荐答案

该值可以省略:

input[onclick]{color: red;}

无关紧要的是,这似乎是一个有趣的用例.我可能会使用类似这样的方法,可能是在边框上设置样式,或者是在文本上设置一些内容,以突出显示具有事件处理程序属性的表单元素(或任何其他元素),以进行调试".

On an unrelated note, this seems like an interesting use case. I would probably use something like this, perhaps styling the border or something instead of the text, in order to highlight form elements (or any other elements) with event handler attributes, for "debugging" purposes.

这篇关于选择具有特定属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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