JQuery 附加不带 id 或类的标记
JQuery Append Tag Without Id or Class
我有重复的nobr标签,我不能添加ID和类。
如何找到包含文本字符串的特定 nobr 标签?
<nobr>Due Date</nobr>
<nobr>Test</nobr>
<nobr>Hello</nobr>
$(document).ready(function() {
$('<nobr>Due Date').append('<span class="ms-formvalidation" title="This is a required field." > *</span>');
});
如果我只是有:
$("nobr").append("*");
那么所有贵族都会受到影响。
$('nobr').filter(function() {
return $(this).text() == 'Due Date';
});
http://api.jquery.com/contains-selector/
$(document).ready(function() {
$("nobr:contains('Due Date')").append('<span class="ms-formvalidation" title="This is a required field." > *</span>');
});
工作示例 : http://jsfiddle.net/EnigmaMaster/FkZcY/
$('nobr').get(1); // get the second one
像这样使用 containts 伪选择器
$("nobr:contains(Test)").append("*");
以下是文档:http://api.jquery.com/contains-selector/
$("nobr").each(function() {
if( $(this).text() == "hello world" ) {
// this is the element with the text in it
}
});
我不是jQuery的人,可能有更好的解决方案。
相关文章:
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 获取打开jquery对话框的button的id
- jQuery mobile not going through ID
- 如何将li类更改为li id's在Jquery中
- 如何使用jQuery迭代id名称的变体(如idname1、idname2)
- 获取不带Id JQuery的复选框值
- 从ID Jquery类获取返回值时出现问题
- attr() 不会更改 id - jquery
- 通过 ID jquery 限制文本区域字符
- 获取选定的行id jquery数据表行选择
- 如何在asp.net mvc中向Action方法发布简单ID(jquery-ajax)
- 添加文本到Javascript Span id jquery
- 动态获取控件ID - JQuery
- 验证选择字段取决于id jquery
- Increment id jquery
- 使用id jquery中的空格
- 根据HTML表的ID jQuery/javaScript对数据进行排序
- 以引号结束id - jquery
- 当draggable被拖放到可拖放区域时添加ID - jQuery Draggables
- 表格ID &jQuery中的名称