javascript - 我想通过 javascript 或 jquery 使用文本本身更改 div 文本

标签 javascript jquery html

我想使用 javascript 或 jquery 更改文本。当脚本获取特定文本(即 $)时,它将更改为 USD。同样,当脚本获取 HK$ 时,它将更改为 HKD。这样我就必须在货币类下更改许多与货币相关的文本。这是我的 HTML 代码:

<div class="ItemSelctionZonePriceBox">
    <font class="Currency">$</font>
    <label id="ctl00_HotelsList_FinalPriceL_4" class="FinalPrice">1,749</label>
</div>

另一个 HTML 代码是:

<div class="ItemSelctionZonePriceBox">
    <font class="Currency">HK$</font>
    <label id="ctl00_HotelsList_FinalPriceL_4" class="FinalPrice">1,749</label>
</div>

我对 JS 和 jQuery 很陌生,所以请帮助我。

最佳答案

您可以使用 jquery .text() 属性通过 class 名称获取值并根据需要更新它们。这是一个 fiddle http://jsfiddle.net/zo4qdnbr/

 var $j_object = $(".Currency");
$j_object.each( function(i) {
    var type=$( this ).text();
if(type=='HK$')
$( this ).html( "HKD" );
if(type=='$')
$( this ).html( "USD" );
} );

关于javascript - 我想通过 javascript 或 jquery 使用文本本身更改 div 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30711324/

相关文章:

javascript - 单选按钮单击是显示英语并单击不显示孟加拉语

javascript - 多响应 AJAX 请求

javascript - 单击导航 slider 时,有没有办法禁用自动滚动的光滑 slider ?

javascript - HTML 表获取选中的复选框和文本元素

html - 使用简单网格系统以移动大小溢出的 Div 容器内容

javascript - 在 JSFiddle 中链接外部 JSON 数据文件

javascript - ExtJS:将模型列转换为网格中的行

html - 如何将无序列表中的列表标签居中?

javascript - android: webview 不使用自定义 WebViewClient 加载 javascript

javascript - Uncaught ReferenceError : function is not defined with onclick with angular form and js