如果链接包含href中的某些内容,则将href更改为this

phi*_*owe 6 javascript jquery href

我想检查href是否包含"即将推出",如果它确实更改了href以转到我的产品页面:

$('a[href$="coming-soon"]').attr('href', '/products.aspx');
Run Code Online (Sandbox Code Playgroud)

不能解决这个问题.

Nic*_*ver 4

$=是“attribute-ends-with”,用于*=“attribute contains”,如下所示:

$('a[href*="coming-soon"]').attr('href', '/products.aspx');
Run Code Online (Sandbox Code Playgroud)