简体   繁体   English

Jquery - 从标签更改文本

[英]Jquery - Change text from label

this is the label, having text = Use 20 kms 这是标签,文字=使用20公里

using jquery i want to Replace the text "20 Kms" with 10 kms" 使用jquery我想用10公里替换文本“20公里”

I get the hand to label like this 我得到这样的标签

 $("label[for='applyDistanceSlab']");

how can i do that... 我怎样才能做到这一点...

$("label[for='applyDistanceSlab']").text("10 kms");
$("label[for='applyDistanceSlab']").text('use 10 kms');

LIVE DEMO 现场演示

text: 文本:

Description: Get the combined text contents of each element in the set of matched elements, including their descendants. 描述:获取匹配元素集中每个元素的组合文本内容,包括它们的后代。

为什么不包括“使用”这个词,并且不必替换:

$("label[for='applyDistanceSlab']").text('Use 10 kms');

你可以做到

$("label[for='applyDistanceSlab']").text($("label[for='applyDistanceSlab']").text().replace("20 Kms", "10 kms"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM