繁体   English   中英

jQuery步进器不会触发更改功能

[英]jQuery stepper doesn't trigger the change function

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

由于在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();
      }
    });
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM