首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Sitecore给出了我需要在jQuery中添加的值

Sitecore给出了我需要在jQuery中添加的值
EN

Stack Overflow用户
提问于 2019-06-04 23:18:44
回答 1查看 33关注 0票数 0

我需要在当前和潜在的位置添加sitecore值。你能在jQuery中使用.pointerValue读取值吗?

我们必须使用html标签来读取值,或者添加一个带有类的标签。

如何读取jQuery中的值?

代码语言:javascript
复制
jQuery(document).ready(function () {

    var currentValue = 30;         

    if (currentValue > 0 && currentValue <= 20) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgG');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    else if (currentValue >= 21 && currentValue <= 38) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgF');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    else if (currentValue >= 39 && currentValue <= 54) {
        jQuery("#tab2 .floating-current").find('div').removeClass();
        jQuery("#tab2 .floating-current").find('div').addClass('pointerbgE');
        jQuery("#tab2 .floating-current .pointerbg .pointerValue").text(currentValue);
    }
    //Potential Value Starts
    var potentialValue = 50;

    if (potentialValue > 0 && potentialValue < 20) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgG');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    else if (potentialValue > 21 && potentialValue < 38) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgF');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    else if (potentialValue > 39 && potentialValue < 54) {
        jQuery("#tab2 .floating-potential").find('div').removeClass();
        jQuery("#tab2 .floating-potential").find('div').addClass('pointerbgE');
        jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text(potentialValue);
    }
    //Potential Value Ends
});
EN

回答 1

Stack Overflow用户

发布于 2019-06-06 03:14:03

正如我在评论中建议的那样,.text()既可以用作Getter,也可以用作Setter。例如,您可以像这样读取值:

代码语言:javascript
复制
var pv = parseInt(jQuery("#tab2 .floating-potential .pointerbg .pointerValue").text().trim());

parseInt()会将字符串值转换为整数。示例:parseInt("43")将返回值为43的Int类型。

.text()将从对象<span class="pointerValue">43</span>中读取TextNode,这将产生字符串"43"

.trim()将删除String对象中的所有空格(如果找到)。你不需要使用它。

因此,.text().trim()将读取字符串"43"并将其传递给parseint(),后者将其类型转换为整数43,并将其存储在变量pv中。

希望这能有所帮助。如果您需要更多帮助,请发布更完整的示例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56446817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档