首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery mouseup()问题

jQuery mouseup()问题
EN

Stack Overflow用户
提问于 2022-10-21 00:13:51
回答 1查看 30关注 0票数 0

我相信这是很简单的事情,我错过了,但我感到茫然。

我有一段jQuery:

代码语言:javascript
复制
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");
  });

它调用一个函数在某些字段号中放置逗号。我不认为这是相关的,但这是一个函数:

代码语言:javascript
复制
 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(“鼠标向上”)工作,只是没有‘数字’。

至于它的价值,我把这个事件放在一个内置滑块在一个拖放网站,我正在编辑。我的“开发”仅限于客户端代码。它上已经有一个事件来检索我认为可能会干扰的新值,但是我不明白它为什么会触发日志或警报。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-25 07:03:20

假设HTML结构如下所示:

代码语言:javascript
复制
  <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>

其余的代码都可以工作,像下面这样修改代码应该会产生所需的输出。

代码语言:javascript
复制
// 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();

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

https://stackoverflow.com/questions/74147507

复制
相关文章

相似问题

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