当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How do I get button to fire click, if first hidden by blur

问题描述:

Hi I have an editable area (textinput or contenteditable) and a button.

I would like the button to hide when the area looses focus -

but clicking on the button will loose focus, hide the button,

BUT THE BUTTON DOES NOT GET ANY CLICK EVENT ANYMORE.... ;-(

  1. first click in the blue text area,
  2. then click the button
  3. the button should fire click and alert - but it doesn't !!

http://jsfiddle.net/3295f/

 <div contenteditable="true"

style="width:300px;height:300px;border:3px solid blue;z-index:100;position:relative;"

onblur="$('button').hide()" >

</div>

<button onclick="alert(1)">pushme</button>

Any idea how to fix this ?

I was never expecting this to be a problem in the first place...

Thanks,

Sebastian

网友答案:

You could use this workaround instead:

<button onmousedown="alert(1)">pushme</button>

http://jsfiddle.net/3295f/2/

分享给朋友:
您可能感兴趣的文章:
随机阅读: