我需要在当前和潜在的位置添加sitecore值。你能在jQuery中使用.pointerValue
读取值吗?
我们必须使用html标签来读取值,或者添加一个带有类的标签。
如何读取jQuery中的值?
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
});
发布于 2019-06-06 03:14:03
正如我在评论中建议的那样,.text()
既可以用作Getter,也可以用作Setter。例如,您可以像这样读取值:
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
中。
希望这能有所帮助。如果您需要更多帮助,请发布更完整的示例。
https://stackoverflow.com/questions/56446817
复制相似问题