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
});

我找到了一个不起作用的解决方案,它只返回"UNDEFINED":

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

What am I missing?

推荐答案

只是一个jQuery太多了:

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

Jquery相关问答推荐

为什么在 jQuery 插件中返回 this.each(function())?

无限滚动jQuery插件

为什么我的 toFixed() 函数不起作用?

如何滚动到AngularJS中的页面顶部?

jQuery:获取所选单选按钮的父 tr

如何使用 jQuery 将分钟转换为小时/分钟并添加各种时间值?

jQuery Keypress 箭头键

如何使用Angular 检测浏览器后退按钮单击事件?

JavaScript 吸管(告诉鼠标光标下像素的 colored颜色 )

$(document).on('click', '#id', function() {}) 与 $('#id').on('click', function(){})

$.each(selector) 和 $(selector).each() 有什么区别

如何在 jquery 中更新(附加到)href?

在 jQuery UI 自动完成上没有检测到结果

如何使用 JQuery 创建一个新的 img 标签,其中包含来自 JavaScript 对象的 src 和 id?

CORS POST 请求可以使用纯 JavaScript,但为什么不使用 jQuery?

Bootstrap datepicker Select 后隐藏

如果一个元素正在被动画,我如何用 jQuery 找出?

在 javascript/浏览器中缓存 jquery ajax 响应

表单 propType 失败:您在没有 `onChange` 处理程序的情况下向表单字段提供了 `value` props

IE 中带有 jQ​​uery ajax 调用的无传输错误