gpt4 book ai didi

javascript - Mootools 到 jquery 对象问题

转载 作者:行者123 更新时间:2023-11-28 01:42:06 25 4
gpt4 key购买 nike

我正在将 Mootools 片段转换为 jQuery,但在将值作为对象返回时遇到问题。

Mootools代码

aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
if (elem) {
var val = elem.get('value').toFloat().round(2);
var v = val ? val : '0';
elem.set({
'value': v
});
Serialize.verifyInput(elems, elem, locks);
}
}

jquery 糟糕的尝试

aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
if (elem) {
var val = $(elem).get('value').toFloat().round(2);
var v = val ? val : '0';
$(elem).val(v);
Serialize.verifyInput(elems, elem, locks);
}
}

我知道 $(elem) 或 $(this) 返回一个对象,其中 Moo elem 返回字符串有人可以解释一下吗?谢谢!

最佳答案

正如您所知,jQuery 和 Mootools 可以存在于同一页面中,无论如何要回答您的问题,请尝试以下操作:

aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
var round = function (inputValue, precision) {
precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0);
return Math.round(inputValue * precision) / precision;
}
if (elem) {
var val = round(parseFloat(elem.value),2);
var v = val ? val : '0';
elem.value = v;
Serialize.verifyInput(elems, elem, locks);
}
}

关于javascript - Mootools 到 jquery 对象问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20800244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com