how to get javaScript event source element?

后端 未结 6 615
夕颜
夕颜 2020-12-23 16:20

Is there a way to retrieve the element source of an inline javaScript call?

I have a button like this:

6条回答
  •  时光说笑
    2020-12-23 17:20

    Your html should be like this:

    
    

    And renaming your input-paramter to event like this

    function doSomething(event){
        var source = event.target || event.srcElement;
        console.log(source);
    }
    

    would solve your problem.

    As a side note, I'd suggest taking a look at jQuery and unobtrusive javascript

提交回复
热议问题