我相信这是很简单的事情,我错过了,但我感到茫然。
我有一段jQuery:
jQuery("span.frm_inline_total").digits();
jQuery(".frm_input_group").on("blur", "input", function () {
jQuery("span.frm_inline_total").digits();
});
jQuery(".frm_range_container input").mouseup(function () {
jQuery("span.frm_inline_total").digits();
console.log("mouse up");
});
jQuery(".frm_range_container input").mousedown(function () {
jQuery("span.frm_inline_total").digits();
console.log("mouse down");
});它调用一个函数在某些字段号中放置逗号。我不认为这是相关的,但这是一个函数:
jQuery.fn.digits = function () {
return this.each(function () {
jQuery(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
})
}我的问题是这个。除了尝试使用mouseup()调用位数()之外,一切都正常工作。它用“控制台.log”记录mouseup()事件,而mousedown()事件正常工作,但不使用mouseup()。...alert(“鼠标向上”)工作,只是没有‘数字’。
至于它的价值,我把这个事件放在一个内置滑块在一个拖放网站,我正在编辑。我的“开发”仅限于客户端代码。它上已经有一个事件来检索我认为可能会干扰的新值,但是我不明白它为什么会触发日志或警报。
发布于 2022-10-25 07:03:20
假设HTML结构如下所示:
<div class="frm_range_container">
<div class="frm_input_group">
<span class="frm_inline_total">Value to replace</span>
<input value="Click me"></input>
</div>
</div>其余的代码都可以工作,像下面这样修改代码应该会产生所需的输出。
// added logs to check in console, digits function is the same
$.fn.digits = function () {
console.log('digits'); // test to see if reaches digits() function
return this.each(function () {
// this should be the correct element.
$(this).text(
$(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")
);
})
}
$(".frm_range_container input").on('mouseup mousedown', function (e) {
console.log(e.type);
$("span.frm_inline_total").digits();
});如果希望仅针对每个frm_range_container中包含的frm_range_container,则可以为此使用$("span.frm_inline_total", this).digits();。
https://stackoverflow.com/questions/74147507
复制相似问题