如何更改 ]中的值[] 我想更改没有任何id的li的特定值,我如何访问此li并将其更改为另一个值。在下面的代码中,我想使用jquery或javascript将“编辑为放置”更改为“编辑”。 <ul class="tabs--primary nav nav-tabs"> <li class="active"><a href="/packages/50411" data-drupal-link-system-path="packages/50411" class="is-active">View<span class="visually-hidden">(active tab)</span></a></li> <li><a href="/packages/50411/edit" data-drupal-link-system-path="packages/50411/edit">Edit</a></li> <li><a href="/packages/50411/delete" data-drupal-link-system-path="packages/50411/delete">Delete</a></li> <li><a href="/packages/50411/edit/enrollment_drop_mode" data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode">Edit as Drop</a></li> <li><a href="/devel/packages/50411" data-drupal-link-system-path="devel/packages/50411">Devel</a></li> </ul> 我想更改没有任何id的li的特定值,我如何访问此li并将其更改为另一个值。在下面的代码中,我想使用... 您可以尝试使用jQuery的:contains()选择器,该选择器 选择包含指定文本的所有元素 : :contains() $('ul li a:contains(Edit as Drop)').text('Edit'); 您可以使用带有属性的<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul class="tabs--primary nav nav-tabs"> <li class="active"><a href="/packages/50411" data-drupal-link-system-path="packages/50411" class="is-active">View<span class="visually-hidden">(active tab)</span></a></li> <li><a href="/packages/50411/edit" data-drupal-link-system-path="packages/50411/edit">Edit</a></li> <li><a href="/packages/50411/delete" data-drupal-link-system-path="packages/50411/delete">Delete</a></li> <li><a href="/packages/50411/edit/enrollment_drop_mode" data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode">Edit as Drop</a></li> <li><a href="/devel/packages/50411" data-drupal-link-system-path="devel/packages/50411">Devel</a></li> </ul>将纯JS bu用于li。 querySelector() document.querySelector('li a[data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode"]').innerText = 'Edit'; 您可以使用nth-child()解决此问题,如下所示: <ul class="tabs--primary nav nav-tabs"> <li class="active"><a href="/packages/50411" data-drupal-link-system-path="packages/50411" class="is-active">View<span class="visually-hidden">(active tab)</span></a></li> <li><a href="/packages/50411/edit" data-drupal-link-system-path="packages/50411/edit">Edit</a></li> <li><a href="/packages/50411/delete" data-drupal-link-system-path="packages/50411/delete">Delete</a></li> <li><a href="/packages/50411/edit/enrollment_drop_mode" data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode">Edit as Drop</a></li> <li><a href="/devel/packages/50411" data-drupal-link-system-path="devel/packages/50411">Devel</a></li> </ul> 我可以感觉到反对投票的到来...但是为什么不添加一个ID并使用innerHTML将值设置为另一个$( ".nav-tabs li:nth-child(4) a" ).html( "Edit" );

问题描述 投票:2回答:4
我想更改没有任何id的li的特定值,我如何访问此li并将其更改为另一个值。在下面的代码中,我想使用jquery或javascript将“编辑为放置”更改为“编辑”。

<ul class="tabs--primary nav nav-tabs"> <li class="active"><a href="/packages/50411" data-drupal-link-system-path="packages/50411" class="is-active">View<span class="visually-hidden">(active tab)</span></a></li> <li><a href="/packages/50411/edit" data-drupal-link-system-path="packages/50411/edit">Edit</a></li> <li><a href="/packages/50411/delete" data-drupal-link-system-path="packages/50411/delete">Delete</a></li> <li><a href="/packages/50411/edit/enrollment_drop_mode" data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode">Edit as Drop</a></li> <li><a href="/devel/packages/50411" data-drupal-link-system-path="devel/packages/50411">Devel</a></li> </ul>

javascript jquery html tags
4个回答
1
投票
您可以尝试使用jQuery的:contains()选择器,该选择器

选择包含指定文本的所有元素


0
投票
您可以使用带有属性的<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul class="tabs--primary nav nav-tabs"> <li class="active"><a href="/packages/50411" data-drupal-link-system-path="packages/50411" class="is-active">View<span class="visually-hidden">(active tab)</span></a></li> <li><a href="/packages/50411/edit" data-drupal-link-system-path="packages/50411/edit">Edit</a></li> <li><a href="/packages/50411/delete" data-drupal-link-system-path="packages/50411/delete">Delete</a></li> <li><a href="/packages/50411/edit/enrollment_drop_mode" data-drupal-link-system-path="packages/50411/edit/enrollment_drop_mode">Edit as Drop</a></li> <li><a href="/devel/packages/50411" data-drupal-link-system-path="devel/packages/50411">Devel</a></li> </ul>将纯JS bu用于li

0
投票
您可以使用nth-child()解决此问题,如下所示:

0
投票
我可以感觉到反对投票的到来...但是为什么不添加一个ID并使用innerHTML将值设置为另一个$( ".nav-tabs li:nth-child(4) a" ).html( "Edit" );
© www.soinside.com 2019 - 2024. All rights reserved.