【问题标题】:jQuery stepper doesn't trigger the change functionjQuery stepper 不会触发更改功能
【发布时间】:2013-05-04 04:55:35
【问题描述】:

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

由于 Firefox 不支持 HTML5 输入 type="number",因此我使用 stepper jQuery plugin

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

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

【问题讨论】:

标签: javascript jquery html firefox haml


【解决方案1】:

检测浏览器不是最佳选择。而是检测对数字的支持

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

【讨论】:

  • 在IE中不是上下三角符号,stepper中有两个&符号如何解决?
  • 您是否将字符集设置为 UTF8?这是否:▴显示一个三角形?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多