让spin.js与提交按钮一起工作

Make spin.js work with submit buttons

本文关键字:按钮 一起 工作 提交 spin js      更新时间:2023-09-26

这个问题已经困扰我一段时间了。我不能让spin.js在提交按钮上工作。

here is a fiddle:

http://jsfiddle.net/xSDGx/24/

如果你注释掉提交按钮,而允许div,那么它工作得很好。

谢谢。参考:

<input type="submit" id="spin">
var spinner;    
var opts = {
lines: 13, // The number of lines to draw
length: 5, // The length of each line
width: 2, // The line thickness
radius:5, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 58, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#fff', // #rgb or #rrggbb or array of colors
speed: 0.9, // Rounds per second
trail: 100, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '57%', // Top position relative to parent
left: '50%' // Left position relative to parent
};
var target = document.getElementById('spin');
var spinner = new Spinner(opts).spin(target);
$(target).data('spinner', spinner);

正如在评论中解释的那样,提交按钮并不意味着包含其他元素。

这就引出了这个问题。

为了解决这个问题,我将提交按钮包装在具有相同宽度和高度的div中。

<div id="wrap">
  <input type="submit">
</div>

你可以使用<button>元素代替,它在默认情况下作为提交按钮:http://jsfiddle.net/fgnass/q6ou3dt7/