English 中文(简体)
Javascript/jQuery——我如何获得被点击元件类别的名称?
原标题:Javascript/jQuery - How do I obtain name of the class of clicked element?

我 go笑和 go笑,我的结论是,我自己很难回答。

我正试图利用jquery或Javales获得一个被点击的元素。 例如,我可以使用“这背书”。

Now I would like to get name of the class of clicked element. Is it even possible? How? And where would I find this kind of information?

  • j 优质文件 - 我可以找到的是方法和gin,没有财产,如果存在,请与我联系。

  • 简讯文件吗? 请再次链接。

  • DOM 文件 - W3C或(联系人)

是什么? - D或 j

最佳回答
问题回答
$(document).click(function(e){
    var clickElement = e.target;  // get the dom element clicked.
    var elementClassName = e.target.className;  // get the classname of the element clicked
});

这支持点击网页的任何地点。 如果被点击的那部分人没有阶级名称,那就将返回无效或空洞。

$( #ele ).click(function() {
    alert($(this).attr( class ));
});

这里是所有属性职能。

http://api.jquery.com/ category/attributes/

你们可以使用元件。

那么,你就可以让所有这些人.,找到你们想要的人。

window.onclick = function(e) {
    var classList = e.srcElement.className.split(/s+/);
    for (i = 0; i < classList.length; i++) {
       if (classList[i] ===  someClass ) {
         //do something
       }
    }
}

页: 1 ery不真正帮助你,但必须

$(document).click(function(){
    var classList =$(this).attr( class ).split(/s+/);
    $.each( classList, function(index, item){
        if (item=== someClass ) {
           //do something
        }
    });
});

如果没有编码,就可以做到这一点。 打开你的浏览器(f12?)的灯光,看你想要的东西。 之后,你想要追踪或点击该项目。

人力部所做的每一项变化都将是几秒钟(或灯光)作为独角的另一色。 (在屏幕上捕获)

例如,每当我把“col子”、 d子母和“col子”等同指向轻。 因此,在这种情况下,被点击的那类人将是血压监视器或冲积器(轻度四级)

“obtain>





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签