如何获取对象的id? [英] How to get the object's id?
本文介绍了如何获取对象的id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取对象的id,我知道id是hola,但我需要在运行时获取它
How to get the id on an object, i know the id is hola, but i need to get it during runtime
alert($('#hola').id);
这个想法是这样的:
<script>
(function ($) {
$.fn.hello = function(msg) {
alert('message ' + msg);
alert('is from ' + this.id); // this.id doesn't work
};
})(jQuery);
$('#hola').hello('yo');
</script>
推荐答案
使用 attr()
读取属性:
Use attr()
to read attributes:
alert($('#hola').attr('id'));
这篇关于如何获取对象的id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文