更新时间:2023-02-24 10:42:05
You could use Attribute Contains Selector [name*="value"]
"a[href*=fruit]"
to select a
elements that contain "fruit"
at href
attribute, .attr(attributeName, function)
, String.prototype.replace()
to replace "apple"
with "orange"
$("a[href*=fruit]").attr("href", function(_, href) {
return href.replace(/apple/, "orange")
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<a href="http://www.domain.com/page/other.jsf?fruit=apple&tree=pine&rock=sedimentary">click me</a>