如何从jQuery中的一组按钮中定位一个按钮,而没有类名称或ID
我如何在不使用类或ID的情况下从一组按钮中定位一个按钮,只是n jQuery
示例:
<body>
<button>Click Me</button>
<button>Click Me</button>
<button class="food">Click Me</button>
<button>Click Me</button>
<button>Click Me</button>
<input type="text">
<!--
<script src="ajax.googleapis.com/ajax/libs/jquery/3.6.0/…>
<script src="index.js"></script>
-->
</body>
How can I target a button from a group of buttons without using a class or id, just n JQuery
Example:
<body>
<button>Click Me</button>
<button>Click Me</button>
<button class="food">Click Me</button>
<button>Click Me</button>
<button>Click Me</button>
<input type="text">
<!--
<script src="ajax.googleapis.com/ajax/libs/jquery/3.6.0/…>
<script src="index.js"></script>
-->
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用jQuery,只有在按钮具有独特的Innertext或Innerhtml时,您才有可能预测。
使用我的示例html从下面:
您需要使用jQuery抓住所有标签,然后根据按钮标签中的内容,通过其InnerHTML或Innertext过滤。
请参阅下面的JS:
With JQuery this would only be possible if the button's had unique innerText or innerHTML that you could then predict.
Using my example HTML from below:
You would need to use JQuery to grab all tags, and then filter that by their innerHTML or innerText depending on what is inside the button tag.
See the below JS:
有很多方法,您可以使用OnClick方法内联HTML。一种粗略的方式---
There many ways, You can use onclick method inline Html. A crude way---