相关疑难解决方法(0)

为什么onclick元素会为label元素触发两次

      window.onload = function(){
         var wow = document.getElementById("wow");
    	 wow.onclick = function(){
    	     alert("hi");
    	 }
      }
Run Code Online (Sandbox Code Playgroud)
    <label id="wow"><input type="checkbox" name="checkbox" value="value">Text</label>
Run Code Online (Sandbox Code Playgroud)

这是我的代码,当我点击"文字"时它会提示两次,但当我点击框时,该onclick元素只会触发一次,为什么?

html javascript

27
推荐指数
2
解决办法
2万
查看次数

如果元素由标签包装,标签是否需要"for"属性?

说我有一套收音机<input>.我不是一个穴居人,所以我知道我需要<label>与那些人<input>交往.由于这里列举原因,我喜欢将单选按钮包装在相应的标签内.

所以,例如:

<fieldset>
    <legend>Should I provide a "for" attribute?</legend>
    <label><input type="radio" name="define_the_for_attribute" id="define_the_for_attribute_yes" value="yes" />Yep, if you know what's good for you</label>
    <label><input type="radio" name="define_the_for_attribute" id="define_the_for_attribute_no" value="no" />Nah, that would be redundant and repetitive</label>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

此包装将相应的单选按钮与标签相关联.我需要定义标签的for属性吗?

<fieldset>
    <legend>Should I provide a "for" attribute?</legend>
    <label for="define_the_for_attribute_yes"><input type="radio" name="define_the_for_attribute" id="define_the_for_attribute_yes" value="yes" />Yep, if you know what's good for you</label>
    <label for="define_the_for_attribute_no"><input type="radio" name="define_the_for_attribute" id="define_the_for_attribute_no" value="no" />Nah, that would …
Run Code Online (Sandbox Code Playgroud)

html accessibility section508

5
推荐指数
1
解决办法
986
查看次数

标签 统计

html ×2

accessibility ×1

javascript ×1

section508 ×1