如何确定在jQuery的匹配元素的元素类型? [英] How can I determine the element type of a matched element in jQuery?

查看:106
本文介绍了如何确定在jQuery的匹配元素的元素类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我匹配ASP.Net生成由ID名称的元素,但我有可能会呈现为根据页面的上下文文本框或标签的一些元素。我需要弄清楚是否匹配是一个文本框或标签,以了解是否由VAL得到的内容()或HTML()。

I'm matching ASP.Net generated elements by ID name, but I have some elements which may render as text boxes or labels depending on the page context. I need to figure out whether the match is to a textbox or label in order to know whether to get the contents by val() or by html().

$("[id$=" + endOfIdToMatch + "]").each(function () {
    //determine whether $(this) is a textbox or label
    //do stuff
});

我发现不工作的解决方案,它只是返回未定义:

I found a solution that doesn't work, it just returns "undefined":

$("[id$=" + endOfIdToMatch + "]").each(function () {
    alert($(this).tagName);
});

我是什么失踪?

推荐答案

刚一jQuery的太多:

Just one jQuery too much:

$("[id$=" + endOfIdToMatch + "]").each(function () {
    alert(this.tagName);
});

这篇关于如何确定在jQuery的匹配元素的元素类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆