In the event response of javascript, we need to obtain the event source object to change its properties, such as changing the src attribute of img. There are two ways to obtain event sources in event response functions:
The first type:
Pass it directly as a parameter. For example
The code copy is as follows:
<div id="myid" onclick="show(this);">text</div>
<script type="text/javascript">
function show(obj){
window.alert(obj.id);
}
</script>
The second type:
Use the hidden event object directly. The event object has a srcElement property that can be accessed directly
The code copy is as follows:
<div id="myid" onclick="show();">text</div>
<script type="text/javascript">
function show(){
window.alert(event.srcElement.id);
}
</script>