jQuery步进器不会触发更改函数

jQuery stepper doesn't trigger the change function

本文关键字:函数 步进 jQuery      更新时间:2023-09-26

我想在更改输入字段时切换提交按钮的可见性。

由于firefox不支持HTML5输入type="number",我使用了步进jQuery插件。

提交按钮最初是隐藏的,当对任何表单字段(包括步进)进行更改时,提交按钮应该显示,但当我更改数字时,不会触发更改事件。

在Chrome中,type="number"字段的默认事件可以正常工作

HAML

.form-actions.hide{
     :style => 'border-top: none; 
     border-bottom: solid 1px; 
     border-bottom-color: #08C;'
}
%button#submit{
     :type => "submit", 
     :class => 'btn btn-primary', 
     :style => 'margin-top: -28px;'
} Submit
JavaScript

if(BrowserDetect.browser == "Firefox"){
   $('#count').stepper();
}
$('#manage form input[type!=submit], select').change(function() {
   $('#manage form .form-actions').show();
});

不适合检测浏览器。而是检测对数字

的支持
function hasNumber() {
  var inp = document.createElement("input");
  inp.setAttribute("type", "number");
  return inp.type !== "text";
}

然后根据你需要的文档

function changeField() {
  $('#manage form .form-actions').show();
}
$(function() {
  if (!hasNumber()) {
  $('#manage form input[type!=submit], select').change(changeField);
    $('#count').stepper({
      onStep: function( val, up ) {
        changeField();
      }
    });
  }
});