`

Disable Element In HTML

阅读更多
disabled attribute
  This Boolean attribute indicates that the form control is not available for interaction. In particular, the click event will not be dispatched on disabled controls. Also, a disabled control's value isn't submitted with the form.
This attribute is ignored if the value of the type attribute is hidden.
eg.
elem.setAttribute("disabled", "disabled");
elem.removeAttribute("disabled");

note:
  In HTML boolean attributes such as disabled and readonly can only legally take the name of the attribute.
eg. disabled="disabled" readonly="readonly"
Most browsers however accept any value for the attribute as being in the affimative.
So the following are equivalent:
disabled="disabled"
disabled
disabled="true"
disabled="false"
disabled="unknown"
disabled="23"
disabled="no"
If you want to remove a disabled attribute in script, use the removeAttribute() method or use the origin dom property.


disabled property
eg.
if (elem.disabled) {
                elem.disabled = false;
} else {
                elem.disabled = true;
}

disable element online demo
<!DOCTYPE html>
<html>
<head>
  <title>disable element</title>
  <script>
  window.onload = function() {
      var lname = document.getElementById("lname");
      var fname =  document.getElementById("fname");
      lname.disabled = false;
      fname.disabled = true;
  }
  </script>
</head>
<body>
    
<form  action="#" method="get">
  <p>First name: <input id="fname" type="text" name="fname" /></p>
  <p>Last name: <input id="lname" type="text" name="lname"   /></p>
  <input type="submit" value="Submit" />
</form>

</body>
</html>




disable element with jQuery online demo
<!DOCTYPE html>
<html>
<head>
    <title>disable element with jquery</title>
   <script id="jquery_172" type="text/javascript" class="library" src="/js/sandbox/jquery/jquery-1.7.2.min.js"></script>
  <script>
  jQuery(function ($) {
      var lname = $("#lname");
      var fname =  $("#fname");
      lname[0].disabled = false;
      fname[0].disabled = true;

      $("#change").click(function() {
          var t =  fname[0];
          if (t.disabled) {
              t.disabled = false;
          } else {
            t.disabled = true;  
          }
      });
  });

  
  </script>
	
</head>
<body>
    
<form  action="#" method="get">
  <p>First name: <input id="fname" type="text" name="fname" /></p>
  <p>Last name: <input id="lname" type="text" name="lname"   /></p>
  <input id="change" type="button" value="en/disable" />
</form>

</body>
</html>




ref:
disabled attribute | disabled property
disabled-false-doesn-enable
分享到:
评论

相关推荐

    解决element-ui里的下拉多选框 el-select 时,默认值不可删除问题

    v-for="(item,index) in abilityOptions" :key="index" :label="`${item.abilityNameZh}(${item.abilityId})`" :disabled="item.required===1" :value="item.abilityId"&gt; ``` 在main.js文件中,定义一个Vue...

    Prototype Cheat Sheet

    - **`replace(element[, html])`**: Replaces an element with HTML content. - **`scrollTo(element)`**: Scrolls the document so that an element is visible. - **`select(element, selector)`**: Selects ...

    elementUI 设置input的只读或禁用的方法

    只读:readonly 在data里定义:readonly: true, 然后在input框里加上readonly就可以了。...DOCTYPE html&gt; &lt;html lang=en&gt; &lt;head&gt; &lt;meta charset=UTF-8&gt; &lt;meta name=viewport content

    selenium-dotnet-2.45.0.zip

    validate that the page in the browser is, in fact, an HTML page. Despite the fact that omitting this check can cause unrecoverable crashes in the driver, there is demand for a mechanism to disable ...

    jQuery aos.js页面滚动元素动画库

    &lt;div class="element" data-aos="fade-in-up"&gt; ``` 3. **初始化aos**:在`&lt;body&gt;`标签的底部或`$(document).ready()`内初始化aos,确保所有DOM元素加载完毕后再执行动画: ```javascript $(document).ready...

    利用cornerstone3渲染dicom文件预览

    Cornerstone 是一个开源的Web DICOM(Digital Imaging and Communications in Medicine)图像查看器库,它提供了在Web浏览器中查看和操作医学影像数据的能力。DICOM是医疗领域广泛使用的标准格式,用于存储、传输和...

    cuteEditor6.0

    and modify certain properties of the element. 默认换行为软回车 (Demo) &lt;br/&gt;Most other editors insert double line returns which can be annoying for clients who are used to editing in ...

    javalruleetcode-fullstack-learning:全栈学习

    disable -&gt; for button, if condition not meet title -&gt; display as tool tip DOM -&gt; doc object model -&gt; allows program and script to access and update content display none -&gt;remove element from dom ex: ...

    ElementUI Tag组件实现多标签生成的方法示例

    :disable-transitions="false" @close="handleClose(tag)" &gt; {{ tag }} class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small" @keyup.enter.native=...

    jquery需要的所有js文件

    "selectstart":"mousedown")+".ui-disableSelection",function(a){a.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}}),a.each(["Width","Height"],function(c,d){...

    04_无头浏览器1

    opt.add_argument('--disable-gpu') web = Chrome(options=opt) ``` 在上面的代码中,我们首先创建了一个ChromeOptions对象,然后使用add_argument方法添加了无头模式和禁用GPU加速的选项。最后,我们使用这些选项...

    jquery1.11.0手册

    index([selector|element]) 数据缓存 data([key],[value]) removeData([name|list])1.7* $.data(ele,[key],[val])1.8- 队列控制 queue(e,[q]) dequeue([queueName]) clearQueue([queueName]) 插件机制 ...

    出现问题a is defined高手帮忙

    // disable text selection on map cover G.mapCover.onselectstart = function() {return false}; return buttonContainerDiv; }; DragZoomControl.prototype.getDefaultPosition = function() { return ...

    Python爬虫实现模拟点击动态页面

    self.driver.find_element_by_class_name('shark-pager-next').click() # 结束时关闭文件 self.file_name.write("\n]") self.file_name.close() # 实例化爬虫并运行 spider = DouyuSpider() spider.run() ``` ...

Global site tag (gtag.js) - Google Analytics