After adding the disabled attribute to the input, how to trigger the click event?

input tag disabled attribute description

  • Disabled input tags are neither usable nor clickable

solution

  • Use the readonly attribute to replace the disabled attribute
  • Coat a parent label, add a click event to the parent label, and set the input style to "pointer-events:none" to remove the mouse event, and then trigger the click event on the parent label through bubbling.

Bubble event
Click on the sub-tag, it will be uploaded layer by layer, and trigger the binding event of the parent tag

cancel bubbling event

e.stopPropagation();
var div2 = document.getElementById("div2");
var div1 = document.getElementById("div1");

 div2.onclick = function(ev){  // 红色面板加事件
     div1.style.display = "block";     stopBubble(ev);//这样就不会再冒泡给父级了 }; document.onclick = function(){      div1.style.display = "none"; } 
function stopBubble(e) {
    //如果提供了事件对象,则这是一个非IE浏览器
   if ( e && e.stopPropagation )
      //因此它支持W3C的stopPropagation()方法
      e.stopPropagation();
  else
  //否则,我们需要使用IE的方式来取消事件冒泡
    window.event.cancelBubble = true;
}

Guess you like

Origin blog.csdn.net/weixin_47020721/article/details/129375052