如何使用JavaScript将“aria-disabled”设置为true
How to set `aria-disabled` as true using JavaScript
我对JS一无所知。但是在我的Ruby中需要一行代码。我有下面的html
。
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="otherButtonClass ui-state-hover ui-state-focus" type="button" role="button" aria-disabled="false">
<button class="otherButtonClass" type="button" role="button" aria-disabled="false" style="display: none;">
<button class="cancelButtonClass" type="button" role="button" aria-disabled="false">
</div>
</div>
我希望JS代码使第一个和第二个按钮可见。代码是什么?
请帮忙。
http://jsfiddle.net/SQ7SH/1/
var buttons = document.querySelectorAll('.ui-dialog-buttonset button');
buttons[0].setAttribute('aria-disabled', true);
buttons[1].setAttribute('aria-disabled', true);
此外,按钮需要关闭标签
当前设置aria-
属性的方式是直接引用属性。
获取:
let el = document.getElementById('foobar');
console.log(el.ariaDisabled); // Should log the current value of aria-disabled.
设置:
let el = document.getElementById('foobar');
el.ariaDisabled = 'true';
console.log(el.ariaDisabled); // Should log 'true'.
参考:Element.ariaDisabled MDN
var buttons = document.getElementsByClassName('otherButtonClass');
for(var i = 0; i < buttons.length; i++){
buttons[i].setAttribute('aria-disabled', 'true');
}
按要求there is needed one line of code
:
document.querySelectorAll('.ui-dialog-buttonset .otherButtonClass').forEach(function (item) {item.setAttribute('aria-disabled', true);});
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- sails.js beforeCreate方法只接收required设置为true的模型属性
- 为什么当async标志设置为false时,xmlhttprequest中的代码可以工作,而当它设置为true时却不能工作
- 设置为负数的变量计算结果为true
- 如何使函数将属性值从 FALSE 设置为 TRUE
- Ext JS 5.1:当可折叠为true时,无法对面板进行标题设置
- 设置“;将标签视为文本“;通过脚本将Google电子表格图表的值设置为true
- 谷歌地图:想在设置draggable为true后直接拖动地图
- 否'访问控制允许来源'当跨域设置为true时,请求的资源错误中存在标头
- 在unslider.js中设置true或false
- 如果选定,如何将所选选项设置为 true
- 使用函数将 V-show 设置为 true 或 false
- 当网格视图设置为 true 时,Jqgrid 在 IE9 中显示“正在加载”
- locaction.reload(true) 会导致强制获取 - 设置 .src 时如何执行此操作
- MongoDB:确保只有一个文档可以将字段设置为 true
- 将 CKEDITOR.config.contentAllow 设置为 true 仍会删除类
- 当我在 Amazon S3 中将安静设置为 true 以在 deleteObjects() 方法中分析安静模式时会发生什
- 当函数在 Javascript 中将其设置为 true 时,布尔值返回 false
- 在验证完成之前,AngularJS 表单$valid设置为 true
- 使用复选框和angular为localStorage设置true/false值