开发者社区 问答 正文

表单控件中元素input的属性readonly的操作实例是什么呢?

表单控件中元素input的属性readonly的操作实例是什么呢?

展开
收起
游客yzrzs5mf6j7yy 2022-03-14 22:15:48 496 分享 版权
1 条回答
写回答
取消 提交回答
  • <button id="btn1">输入域只读</button>
    <button id="btn2">输入域可读写</button>
    <input id="test" value="内容" readonly>
    <script>
    btn1.onclick = function(){
        test.setAttribute('readonly','readonly');
    }
    btn2.onclick = function(){
        test.removeAttribute('readonly');
    }    
    </script>
    
    2022-03-14 22:16:01
    赞同 展开评论
问答地址: