正在尝试基于JQuery Attribute Contains更改h1标记
Trying to change an h1 tag based on the JQuery Attribute Contains
我在一个动态生成的页面上有一个链接,它的href看起来像<a href="/ListJobs/ByCustom/Job-Category/Keyword-Accounting-Finance/">Accounting/Finance</a>
或<a href="/ListJobs/ByCustom/StationLocation/Keyword-KCCI-TV/">KCCI-TV</a>
,我需要根据链接的Job Category或StationLocation部分更改h1标记。我试过使用
if ($("table a[href='/ListJobs'][href='/ByCustom'][href='/StationLocation']")) {
alert($('table a').attr("href"));
} else {
alert("Category");
$('#mainbody h1').html("Careers by Category");
}
以及包括在内的许多其他变体
$("table a [href|='/ListJobs/ByCustom/Job-Category']
所有的努力都没有达到预期的效果。我应该使用什么来查看href是否包含我需要的字符串部分,以便相应地更改h1标记?
$("table a").each(function() {
if (this.href.indexOf('StationLocation') != -1) {
alert($('table a').attr("href"));
} else {
alert("Category");
$('#mainbody h1').html("Careers by Category");
}
});
使用^="starts with"运算符怎么样?
if ($("table a[href^='/ListJobs'][href^='/ByCustom'][href^='/StationLocation']")) {
alert($('table a').attr("href"));
} else {
alert("Category");
$('#mainbody h1').html("Careers by Category");
}
http://api.jquery.com/attribute-starts-with-selector/
相关文章:
- 使用jquery contains获取一个元素并添加类
- 如何让firefox使用style['attribute name']=设置样式属性
- “*[attribute ^="string”是如何/为什么是有效的querySelector?(JS bug
- 正在尝试基于JQuery Attribute Contains更改h1标记
- Cookie Domain contains Dot?
- JS - jQuery inarray ignoreCase() and contains()
- browserSync + Gulp,得到错误 => TypeError: _.contains 不是一个函数
- Javascript - Time Return Attribute
- JSTL if-then-else session attribute
- $watchCollection id attribute & ng-model
- Google Maps Javascript API - bounds.contains method
- element.classList.contains() 在 JavaScript 中究竟是如何工作的
- Transcluding HTML that contains ng-binds
- jQuery Remove attribute in ajax
- contains() 总是返回 true
- Javascript: Jquery Select-Object-by-Attribute-Value doen'
- Restangular - _.contains() 不是一个函数
- Google Maps API v3 - google.maps.geometry.poly.contains位置第一次
- 有没有办法在jQuery :contains()选择器中使用多个字符串
- 如何使用 javascript 中的 classList.contains 在引导下拉菜单中获取 li 类