- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Javascript 和 Jquery 的新手。我想通过 Jquery 将 CSS 类添加到以大写字母开头的行。 HTML 代码由 Django Admin 自动生成。例如这一行:
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3641" /></td><th class="field-__str__"><a href="/admin/app/bigram/3641/">Ramës Mapo ---> </a></th></tr>
必须有红色背景。
这是我的源代码,但它不起作用。
<!DOCTYPE html>
<html>
<head>
<style>
important {background-color:red}'
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
var t = document.getElementsByClassName("field-__str__").textContent;
//alert(t);
if(t.charAt(0) === t.charAt(0).toUpperCase())
{
$("field-__str__ tr th a").addClass("important");
}
</script>
</head>
<body>
<table id="result_list">
<thead>
<tr>
<th scope="col" class="action-checkbox-column">
<div class="text"><span><input type="checkbox" id="action-toggle" /></span></div>
<div class="clear"></div>
</th>
<th scope="col" class="column-__str__">
<div class="text"><span>Bigram</span></div>
<div class="clear"></div>
</th>
</tr>
</thead>
<tbody>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3641" /></td><th class="field-__str__"><a href="/admin/app/bigram/3641/">Ramës Mapo ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3640" /></td><th class="field-__str__"><a href="/admin/app/bigram/3640/">Edi Ramës ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3554" /></td><th class="field-__str__"><a href="/admin/app/bigram/3554/">përmbysi lulishten ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3553" /></td><th class="field-__str__"><a href="/admin/app/bigram/3553/">bredhat përmbysi ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3552" /></td><th class="field-__str__"><a href="/admin/app/bigram/3552/">preu bredhat ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3551" /></td><th class="field-__str__"><a href="/admin/app/bigram/3551/">tregon preu ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3550" /></td><th class="field-__str__"><a href="/admin/app/bigram/3550/">sheshit tregon ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3549" /></td><th class="field-__str__"><a href="/admin/app/bigram/3549/">gjelbërim sheshit ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3548" /></td><th class="field-__str__"><a href="/admin/app/bigram/3548/">Flet gjelbërim ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3547" /></td><th class="field-__str__"><a href="/admin/app/bigram/3547/">bashkie Flet ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3546" /></td><th class="field-__str__"><a href="/admin/app/bigram/3546/">kryetar bashkie ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3545" /></td><th class="field-__str__"><a href="/admin/app/bigram/3545/">Rama kryetar ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3544" /></td><th class="field-__str__"><a href="/admin/app/bigram/3544/">Edi Rama ---> </a></th></tr>
<tr class="row1"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3543" /></td><th class="field-__str__"><a href="/admin/app/bigram/3543/">miratoi Edi ---> </a></th></tr>
<tr class="row2"><td class="action-checkbox"><input class="action-select" name="_selected_action" type="checkbox" value="3542" /></td><th class="field-__str__"><a href="/admin/app/bigram/3542/">projektin miratoi ---> </a></th></tr>
</tbody>
</table>
</body>
</html>
谢谢大家!
最佳答案
缺少 .
选择器 $("field-__str__ tr th a").addClass("important");
,还有 tr
不是 .field-__str__
的子节点。将 javascript
包装在 .ready()
中,以便在加载 document
时调用。
$(function() {
var t = $(".field-__str__");
for (var i = 0; i < t.length; i++) {
var text = t.eq(i).text().trim().charAt(0);
if (text === text.toUpperCase()) {
t.eq(i).find("a").addClass("important");
}
}
})
<!DOCTYPE html>
<html>
<head>
<style>
.important {
background-color: red
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var t = $(".field-__str__");
for (var i = 0; i < t.length; i++) {
var text = t.eq(i).text().trim().charAt(0);
if (text === text.toUpperCase()) {
t.eq(i).find("a").addClass("important");
}
}
})
</script>
</head>
<body>
<table id="result_list">
<thead>
<tr>
<th scope="col" class="action-checkbox-column">
<div class="text"><span><input type="checkbox" id="action-toggle" /></span>
</div>
<div class="clear"></div>
</th>
<th scope="col" class="column-__str__">
<div class="text"><span>Bigram</span>
</div>
<div class="clear"></div>
</th>
</tr>
</thead>
<tbody>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3641" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3641/">Ramës Mapo ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3640" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3640/">Edi Ramës ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3554" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3554/">përmbysi lulishten ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3553" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3553/">bredhat përmbysi ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3552" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3552/">preu bredhat ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3551" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3551/">tregon preu ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3550" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3550/">sheshit tregon ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3549" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3549/">gjelbërim sheshit ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3548" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3548/">Flet gjelbërim ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3547" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3547/">bashkie Flet ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3546" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3546/">kryetar bashkie ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3545" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3545/">Rama kryetar ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3544" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3544/">Edi Rama ---> </a>
</th>
</tr>
<tr class="row1">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3543" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3543/">miratoi Edi ---> </a>
</th>
</tr>
<tr class="row2">
<td class="action-checkbox">
<input class="action-select" name="_selected_action" type="checkbox" value="3542" />
</td>
<th class="field-__str__"><a href="/admin/app/bigram/3542/">projektin miratoi ---> </a>
</th>
</tr>
</tbody>
</table>
</body>
</html>
关于javascript - 将 CSS 类添加到以大写字母开头的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36824462/
我遇到了一个小问题。我想利用字符串中的双字母。我设法编译了一个程序,但没有成功。 #include #include #include std::string::iterator functio
我想让我在文本字段中写的所有内容都是大写字母。在我写作时,而不是在失去焦点之后。 我如何使用 jQuery 做到这一点? 最佳答案 我会为此使用 CSS。 只需将 text-transform: up
<% '****************************** '函数:gen_key(digits)&nb
我有一个表单,我希望用户只输入字母、数字 我想限制他们 使用数字作为第一个值 例如。 1abc 使用大写字母1ABc 使用空格1 ab CD d5 我只想要abc1 OR a1bc OR f25fhg
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
恢复MySQL数据库后,我可以保留所有大写字母名称的表。但 View 名称改为小写字母。 我可以更改一些设置以使 View 在恢复数据库后保留大写字母名称吗? 附注我可以在恢复后再次将 View 更改
总的来说,我是 PDO 和 MySQL 的新手。我正在从即将弃用的 MySQL 切换到 PDO,我有一些问题想更好地了解 MySQL 查询的工作原理。 我目前有这个功能,我不明白表格行前的大写U.&M
仅当所有大写字母位于单词中间时,我才需要匹配它们。例如,RegExr 将与字母 E 匹配。 someThings 代表字母 T。如果大写字母从单词的开头开始,则它不应该匹配。 这个正则表达式几乎匹配它
这个问题已经有答案了: What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? (25 个回答)
我需要按字母顺序相应地排列名称。我设法获得了所需的输出。但是,当我用第一个大写字母键入名称时,例如:Peter,输出是不同的。 EG 输入:Peter Paul John Mary EG 输出:第一个
我一直在谷歌上搜索,但没有找到我的问题的答案: 如何使用正则表达式检查字符串是否至少包含以下各项: 大写字母 小写字母 数字 特殊字符:~`!@#$%^&*()-_=+\|[{]};:'",/? 所以
所以我找到了一个适用于数字然后字母的代码,我尝试修改,以便用户在单元格中输入数据需要是 ex:"52TSQ1234512345" 。我知道他们必须输入 ex: "12PQS" (数字和字母是示例,它可
我正在尝试编写代码,以便从字符串(文本)中删除“坏”单词。 如果该词后面有逗号或任何特殊符号,则该词是“坏”的。如果该单词仅包含 a 到 z(小写字母),则该单词并不“坏”。 所以,我想要达到的结果是
Visual Studio 2012 c++ 文档指出 _ReadBarrier和 _WriteBarrier内在函数现在是 deprecated: The _ReadBarrier, _WriteB
在我的站点中,我提供了一个选项来上传带有 .jpg 和 .JPG 扩展名的图像。它们都可以工作,我可以在服务器本身上看到它们。 当我尝试在浏览器中查看带有 .jpg 扩展名的照片时,将它们命名为 na
我刚刚看到这在技术上是可行的,我无法解决的唯一错误是每次测试时打印的最后一个 ASCII 字符,我也在不使用 的情况下进行了测试。姓名 变量,我的意思是在 ASCII 中的任何小写字母减去 32 应该
我得到了这样的序列: (\$ \# \A \( \* \& \9 \8 \7 \Z \f) 我想过滤掉其中的大写 ASCII 字母,如\A 和\Z 我试图在标准库中查找,但没有运气。 有谁能够帮助我?
我已经搜索过 SO 和 Google,我发现的大多数示例似乎都没有按预期工作(或者没有结合所有这些元素)。我正在尝试创建一个 Regex 表达式,如果字符串包含 至少 字符串中的以下 anywhere
我需要从 mysql 中选择有关查询字符串的结果。让我们的字符串是:Z 和 z(大写和小写) 数据库的样子: url_id test_char 1 Z 2
到目前为止,我们在任何地方都没有发现关于这种非常奇怪的效果的信息。 有一段时间(不知 Prop 体从什么时候开始),大写字母 S 在 Windows 浏览器中的呈现就像它向右移动了一两个像素一样。 这
我是一名优秀的程序员,十分优秀!