obj.attr('id')返回undefined但obj.getAttribute('id')有效.为什么?

Mar*_*n W 1 html javascript jquery attr getattribute

在我的JS obj.attr('...')和obj.prop('...')不起作用,但obj.getAttribute('...')运作良好.

你能告诉我为什么吗?

function ShowTips(obj) // show tip in element's attribute
{
    var msg = obj.attr("tip"); // failed. 
    alert(msg);
}

function startPoint() // start from here.
{
    var obj = document.getElementById("img01");
    ShowTips(obj);
}
Run Code Online (Sandbox Code Playgroud)

Fue*_*fee 5

obj是一个DOM元素,而不是一个jQuery对象.在$()中包装obj以使其客观化:

$(obj).attr("tip");