我在我的 Windows 10 UWP winjs 应用程序中创建了一个工具栏,我想禁用一些按钮。
我像这样将属性附加到按钮:
new WinJS.UI.Command(null, {
disable: true,
id: 'cmdSave',
label: 'save',
section: 'primary',
type: 'button',
icon: 'save',
onclick: clickbuttonprintout()
});
我查看了 winjs 的 css 文件,发现了很多禁用的标签。是否可以将按钮设置为禁用,就像我在上面附加了其他属性一样?
最佳答案
想通了:
您选择该按钮,将其设置为禁用,然后对其进行处理。
var thisBtn = document.getElementById('cmdSave');
thisBtn.disabled = true;
WinJS.UI.process(btn); //this is key
考虑到这一点,我设置了一个函数,这样我就可以将不同的按钮传递给它:
function disableButton(buttonID){
var btn = document.getElementById(buttonID);
btn.disabled = true;
WinJS.UI.process(btn);
}
附言
即使这不是问题的一部分,它也可能对人们有所帮助。
编辑按钮上的属性怎么样?我做了这个功能来编辑 winjs 按钮上的任何属性:
function changeButtonAttributes(buttonId, element, attribute) {
var btn = document.getElementById(buttonId); //select button
btn.winControl[element] = attribute; //button.element = attribute
WinJS.UI.process(btn); //process all
}
希望对您有所帮助:)
关于javascript - 如何将工具栏中的按钮设置为禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34897571/