Home >Web Front-end >JS Tutorial >JavaScript code that activates input when checked, otherwise disabled_form effects

JavaScript code that activates input when checked, otherwise disabled_form effects

WBOY
WBOYOriginal
2016-05-16 18:39:361205browse
复制代码 代码如下:

window.onload = function(){
var price = document.getElementById('price');
price.disabled = true;
price.style.padding = '2px 3px';
price.style.background = '#eee';
price.style.border = '1px solid #ccc';
var tj = document.getElementById('tj');
tj.onclick = function(){
if(tj.checked == true){ //可编辑
price.disabled = false;
price.style.background = '#fff';
price.style.border = '2px solid #ff7d00';
price.style.padding = '2px 3px';
price.focus();

} else {
price.disabled = true;
price.style.background = '#eee';
price.style.border = '1px solid #ccc';
price.style.padding = '2px 3px';
}
}

}

复制代码 代码如下:


价格: 特价


唯一的可去之外是加了一点美化,使用户体验更加一层楼,其中包括边框的加粗,焦点的获取,checkbox边框线的隐藏等等。
测试代码

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行
]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn