suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Es gibt ein IMG-Tag in einem Div. Warum binde ich Ereignisse an das Div und wenn ich das angeklickte Objekt drucke, ist es manchmal das IMG-Objekt anstelle des Div-Objekts?

Beim Anklicken des Bildes wird die Funktion ebenfalls ausgelöst, ich habe sie aber nicht an das Bild gebunden. .

迷茫迷茫2813 Tage vor696

Antworte allen(4)Ich werde antworten

  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:31:01

    用 event.currentTarget,event.target返回触发事件的元素,event.currentTarget返回绑定事件的元素

    Antwort
    0
  • 世界只因有你

    世界只因有你2017-06-12 09:31:01

    请显示choseIcon()方法是怎样写的。

    Antwort
    0
  • 黄舟

    黄舟2017-06-12 09:31:01

    应该是img在p里面你点击图片也是可以出发事件的你打印然后就出来了

    Antwort
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-12 09:31:01

    因为有事件冒泡的机制,所以点击img时候也会触发父级p的绑定事件。

    Antwort
    0
  • StornierenAntwort