[英]Change submit button text and disable it in iOs
I have this piece of js code, it works on pc (change text to 'adding...' and disables a button). 我有这段js代码,它可以在PC上运行(将文本更改为“添加...”并禁用按钮)。 But on iOs devices only form is submitted, text is not changing.
但是在iOs设备上,仅提交表单,文本未更改。 Any ideas?
有任何想法吗?
$(".moveToBasket").click(function() {
var form = $(this).closest('form');
var button = $(this);
button.attr('value', 'Adding...');
form.on('submit', function() {
button.prop("disabled", true);
});
});
PS .moveToBasket class html element is 'input type="submit"' PS .moveToBasket类html元素为'input type =“ submit”'
I had the same problem a few days ago. 几天前我遇到了同样的问题。 It seems there are other people who confirmed the bug in Safari: https://github.com/rails/jquery-ujs/issues/306
似乎还有其他人确认了Safari中的错误: https : //github.com/rails/jquery-ujs/issues/306
I solved it like this: 我这样解决了:
$('body').on('submit', form, function formSubmitHandler(event){
// Shadow the form to prevent infinite loop
var form = event.target;
event.preventDefault();
// If <input type="submit">
button.attr('value', 'Adding...');
// If <button>Add</button>
button.text('Adding...');
button.prop('disabled', true);
// Submit the form in a different tick
setTimeout(function() {
form.submit();
}, 10);
});
I hope it helps. 希望对您有所帮助。
Can you send me the HTML so I can see what needs to be done, 您可以将HTML发送给我,以便我看到需要做什么,
If it's a button element, you can do button.text('adding...') 如果是按钮元素,则可以执行button.text('adding ...')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.