<legend id='WZIZN'><style id='WZIZN'><dir id='WZIZN'><q id='WZIZN'></q></dir></style></legend>

  • <small id='WZIZN'></small><noframes id='WZIZN'>

      <bdo id='WZIZN'></bdo><ul id='WZIZN'></ul>
    <tfoot id='WZIZN'></tfoot>

      1. <i id='WZIZN'><tr id='WZIZN'><dt id='WZIZN'><q id='WZIZN'><span id='WZIZN'><b id='WZIZN'><form id='WZIZN'><ins id='WZIZN'></ins><ul id='WZIZN'></ul><sub id='WZIZN'></sub></form><legend id='WZIZN'></legend><bdo id='WZIZN'><pre id='WZIZN'><center id='WZIZN'></center></pre></bdo></b><th id='WZIZN'></th></span></q></dt></tr></i><div id='WZIZN'><tfoot id='WZIZN'></tfoot><dl id='WZIZN'><fieldset id='WZIZN'></fieldset></dl></div>

        处理“onclick"纯 JavaScript 事件

        时间:2023-09-05
          <tbody id='hKmDw'></tbody>

        <legend id='hKmDw'><style id='hKmDw'><dir id='hKmDw'><q id='hKmDw'></q></dir></style></legend>

        1. <i id='hKmDw'><tr id='hKmDw'><dt id='hKmDw'><q id='hKmDw'><span id='hKmDw'><b id='hKmDw'><form id='hKmDw'><ins id='hKmDw'></ins><ul id='hKmDw'></ul><sub id='hKmDw'></sub></form><legend id='hKmDw'></legend><bdo id='hKmDw'><pre id='hKmDw'><center id='hKmDw'></center></pre></bdo></b><th id='hKmDw'></th></span></q></dt></tr></i><div id='hKmDw'><tfoot id='hKmDw'></tfoot><dl id='hKmDw'><fieldset id='hKmDw'></fieldset></dl></div>

            <tfoot id='hKmDw'></tfoot>
              <bdo id='hKmDw'></bdo><ul id='hKmDw'></ul>

                  <small id='hKmDw'></small><noframes id='hKmDw'>

                  本文介绍了处理“onclick"纯 JavaScript 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这真的很简单,但我对 JavaScript 还是很陌生,只是发现了 JSFiddle.我正在尝试使用 getElementById() 查找元素以禁用和启用按钮.我错过了什么?

                  This is really straight forward but I'm still fairly new to JavaScript and just found JSFiddle. I'm trying to find the element with the getElementById() to disable and enable a button. What am I missing?

                  <form name="frm" > 
                    <div id="chkObj"> 
                      <input type="checkbox" name="setChkBx" onclick="basicList.modifyAndEnableButton(this)"></input>        
                  </div>
                  <div id="Hello"> 
                      <input type="button" name="btn" value="Hello"></input>        
                    </div>
                  </form>
                  

                  这是我用来添加复选框的列表,因为会有多个:

                  This is a list that I am using to add checkboxes because there is going to be more than one:

                   var basicList = {
                      'items': {},
                      'modifyAndEnableButton': function(obj1) {
                          var element = document.getElementsByName("btn");
                          if (obj1.checked == true && element.getAttribute('disabled') == false) {
                              element.getAttribute('disabled') = true;
                              this.addRecord(obj2);
                          } else if (element.getAttribute('disabled') == true) {
                              if (hasItems == false) {
                                  element.getAttribute('disabled') = false;
                              }
                          } 
                      }
                  };
                  

                  http://jsfiddle.net/Arandolph0/E9zvc/3/

                  推荐答案

                  所有浏览器都支持这个(参见此处的示例):

                  All browsers support this (see example here):

                  mySelectedElement.onclick = function(e){
                      //your handler here
                  }
                  

                  但是,有时您想添加一个处理程序(而不是更改同一个处理程序),更一般地说,如果可用,您应该使用 addEventListener(IE8 需要 shim-)

                  However, sometimes you want to add a handler (and not change the same one), and more generally when available you should use addEventListener (needs shim for IE8-)

                  mySelectedElement.addEventListener("click",function(e){
                     //your handler here
                  },false);
                  

                  这是一个工作示例:

                  var button = document.getElementById("myButton");
                  button.addEventListener("click",function(e){
                      button.disabled = "true";
                  },false);
                  

                  还有html:

                  <button id='myButton'>Hello</button>
                  

                  (小提琴)

                  这里有一些有用的资源:

                  (fiddle)

                  Here are some useful resources:

                  • addEventListener on mdn
                  • DOM 规范中的点击事件
                  • 点击示例在MDN JavaScript教程中
                  • addEventListener on mdn
                  • The click event in the DOM specification
                  • Click example in the MDN JavaScript tutorial

                  这篇关于处理“onclick"纯 JavaScript 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:假“点击"激活 onclick 方法 下一篇:为什么“事件"在 Chrome 中全局可用,但在 F

                  相关文章

                  最新文章

                    • <bdo id='rP005'></bdo><ul id='rP005'></ul>
                    <i id='rP005'><tr id='rP005'><dt id='rP005'><q id='rP005'><span id='rP005'><b id='rP005'><form id='rP005'><ins id='rP005'></ins><ul id='rP005'></ul><sub id='rP005'></sub></form><legend id='rP005'></legend><bdo id='rP005'><pre id='rP005'><center id='rP005'></center></pre></bdo></b><th id='rP005'></th></span></q></dt></tr></i><div id='rP005'><tfoot id='rP005'></tfoot><dl id='rP005'><fieldset id='rP005'></fieldset></dl></div>

                    <small id='rP005'></small><noframes id='rP005'>

                    <tfoot id='rP005'></tfoot>
                    1. <legend id='rP005'><style id='rP005'><dir id='rP005'><q id='rP005'></q></dir></style></legend>