开发者

getAttribute of dom object calling function

I am using jqueryui.com's autocomplete function and I would like it to add the values in a datalist if the input has the list attribute and a remote json source if it has the src attribute.

As far as I can tell I should be able to do:

$(function() {
    $( ".keywords" ).autocomplete({
        //determine dom object that called this
        //if dom object has list开发者_开发技巧 attribute
            //walk though dataset with id = list attribute
                //add to source
        //elseif dom object has src attribute
            //add url data to source
        }
    });
});

but I am not very familiar with javascript, how would I extract the dom object, then test it's attributes?


No, you can't do it directly like that, but you could do this:

$( '.keywords' ).each(function() {
  var field = this;
  $(field).autocomplete({
    blah: $(field).attr('blah'), // etc
  });
});

You don't really need the "field" intermediate to hold the this value, but I think it makes things a little less confusing in cases like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜