最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to Convert event object to string in JavaScript? - Stack Overflow

programmeradmin7浏览0评论

I am trying to get which event is occured ::

function getEvent(){
    alert(window.event);
}

I am getting below event object. I want it in string to pare. if event onclick event then I want to do the action. how can I get it in string? or how can I convert event object to string?

[object MouseEvent]

I am trying to get which event is occured ::

function getEvent(){
    alert(window.event);
}

I am getting below event object. I want it in string to pare. if event onclick event then I want to do the action. how can I get it in string? or how can I convert event object to string?

[object MouseEvent]
Share Improve this question asked Oct 17, 2012 at 10:34 AsmitaAsmita 1,1903 gold badges10 silver badges31 bronze badges 1
  • Why do you need this? Can you give an example? – Rune FS Commented Oct 17, 2012 at 10:39
Add a ment  | 

5 Answers 5

Reset to default 7

Use the type property. window.event.type

You'd probably want:

function getEvent(){
    alert(window.event.type);
}

https://developer.mozilla/en-US/docs/DOM/event.type

you can easily get it by type like this

function getEvent(){
    alert(window.event.type);
}

More info here

http://www.quirksmode/js/events_access.html

http://www.quirksmode/js/events_properties.html

use the type property to read out the type:

function getEvent(){
    alert(window.event.type);
}

Use the event.type property, for example

<div id="a" onclick="alert(event.type)">Click This</div>

<div id="b">And This</div>​

Javascript:

var func = $('#a').attr('onclick');
$('#b').mouseover(function(e) {
    func(e)
});

DEMO: http://jsfiddle/4tLms/ ​

发布评论

评论列表(0)

  1. 暂无评论