更改 jquery 对话框按钮上的文本会影响按钮高度
我有一个 jquery 模式对话框,我试图在单击按钮后更改按钮上显示的文本。例如,“发送”按钮更改为“正在发送...”,并且在单击时被禁用。
这一切都工作正常,但有一个问题:按钮失去了所有内部填充,并且按钮边框正好包裹在文本周围。
$('#email-dialog').dialog({
autoOpen: false,
height: 'auto',
width: 'auto',
modal: true,
buttons: {
"Send": function() {
$(".ui-dialog-buttonpane button:contains('Send')").button("disable");
$(".ui-dialog-buttonpane button:contains('Send')").button().html('Sending...');
$.ajax({
type: "POST",
url: post_path,
data: form_data,
dataType: 'JSON',
success: function(data) {
if (data.success) {
$("#email-dialog").dialog("close");
} else {
updateErrors(data.errors);
$(".ui-dialog-buttonpane button:contains('Sending...')").button("enable");
$(".ui-dialog-buttonpane button:contains('Sending...')").button().text('Send');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Error: ' + textStatus + ' ' + errorThrown);
$(".ui-dialog-buttonpane button:contains('Sending...')").button("enable");
$(".ui-dialog-buttonpane button:contains('Sending...')").button().text('Send');
}
});
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
});
我尝试过 html() 和 text() 方法。我在这里错过了一些非常明显的东西吗?
I have a jquery modal dialog, and I am trying to change the text shown on a button after it is clicked. So, for example, the Send button gets changed to 'Sending...' and is disabled when it is clicked.
This all works fine, with one problem: the button loses all of its internal padding, and the button border wraps right around the text.
$('#email-dialog').dialog({
autoOpen: false,
height: 'auto',
width: 'auto',
modal: true,
buttons: {
"Send": function() {
$(".ui-dialog-buttonpane button:contains('Send')").button("disable");
$(".ui-dialog-buttonpane button:contains('Send')").button().html('Sending...');
$.ajax({
type: "POST",
url: post_path,
data: form_data,
dataType: 'JSON',
success: function(data) {
if (data.success) {
$("#email-dialog").dialog("close");
} else {
updateErrors(data.errors);
$(".ui-dialog-buttonpane button:contains('Sending...')").button("enable");
$(".ui-dialog-buttonpane button:contains('Sending...')").button().text('Send');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Error: ' + textStatus + ' ' + errorThrown);
$(".ui-dialog-buttonpane button:contains('Sending...')").button("enable");
$(".ui-dialog-buttonpane button:contains('Sending...')").button().text('Send');
}
});
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
});
I have tried with both the html() and text() methods. Am I missing something really obvious here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看按钮实际呈现的 html,您会注意到
因此,为了让您的代码正常工作,您可能应该执行以下操作:
编辑: 根据 mmcnickle 的评论,看起来 jQuery UI 按钮有一个可以使用的 label 属性。例如
jsFiddle 的实际应用
jQuery UI 按钮标签文档
If you have a look at the html at the button actually renders you'll notice that there is a
<span>
inside the<button>
tag.So to get your code to work, you should probably do something like:
EDIT: As per mmcnickle's comment, it looks like the jQuery UI Button has a label property that you can use. E.g.
jsFiddle of it in action
jQuery UI Button Label Documentation
您可以通过更改
label
选项来更改 jQuery UI 按钮中的文本:You change the text in a jQuery UI button, by changing the
label
option: