如何在javascript中选择包含特定字符串的所有id标签? [英] How do you select all id tags that contain a certain string in javascript?

查看:90
本文介绍了如何在javascript中选择包含特定字符串的所有id标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET应用程序,它提供了多个问题,并提供了给出答案的解释。

I have an ASP.NET application that renders multiple questions with the option to provide an explanation for the answers given.

<label for="[<%:count %>].AnswerExplanation_<%: i+1 %>" id="[<%:count %>].toggleExplanation_<%: i+1 %>"><strong>Add Explanation</strong></label>
<br /><br />
<div id="[<%:count %>].Explanation_<%: i+1 %>">
    <textarea id="[<%:count %>].AnswerExplanation_<%: i+1 %>" name="[<%:count %>].AnswerExplanation_<%: i+1 %>" class="ckedit"></textarea>
</div>

因此您将拥有与[X] .AnswerExplanation_Y相对应的[X] .toggleExplanation_Y的ID

so you will have id's like "[X].toggleExplanation_Y" corresponding to "[X].AnswerExplanation_Y"

我正在编写一个javascript函数来显示/隐藏AnswerExplanation div,并且正在寻找一种方法来选择包含toggleExplanation的每个id我应该能够得到从那里开始。

I am writing a javascript function to show/hide the AnswerExplanation divs, and was looking for a way to select every id containing "toggleExplanation" I should be able to get the rest from there.

推荐答案

尝试使用属性包含收集器

$('label[id*="toggleExplanation"]')

这篇关于如何在javascript中选择包含特定字符串的所有id标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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