我一定错过了一些非常愚蠢的东西,但我就是无法从 Google Apps 的对话框中获取界面按钮。
如果我尝试通过“单击”功能将 this
对象中的 disabled
设置为 false,则该按钮会启用。但如果我尝试 $('#dialog-ok-button').disabled = false;
它什么也不做!!!:
代码(我知道代码中有重复的操作,这是一个比较我尝试过的示例!):
...
<button class="action" id="dialog-ok-button" >OK</button>
...
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
$('#dialog-ok-button').click(onExecuteClick);
});
function onExecuteClick() {
this.disabled = true; //disables the button
google.script.run
.withSuccessHandler(
function(msg, element) {
showStatus('Execution successful.');
//---------HERE---------
element.disabled = false; //this works!
$('#dialog-ok-button').disabled = false; //this NEVER works!
//---------HERE---------
})
.withFailureHandler(....)
.withUserObject(this)
.doSomething();
function showStatus(msg, classId) {
//-------HERE TOO---------
$('#dialog-ok-button').disabled = false; //this NEVER works!
$('#script-status').removeClass().html(msg); //this works!
//-------HERE TOO---------
if (classId) {
$('#script-status').addClass(classId); //this works!
}
}
</script>
最佳答案
当您使用 jQuery 选择器时,您需要使用 prop
启用它
$('#dialog-ok-button').prop('disabled',false); //Or true to disable it
关于javascript - 如何从 Google Apps 对话框中获取按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30627249/