开发者

jquery - how to select all input with this attribute?

I've the following html code:

<input data-autocomplete="/items/autocomplete_part_title?locale=en" data-id-element="#autocomplete_38219" id="item_item_parts_attributes_0_开发者_运维知识库autocomplete_part_id" name="item[item_parts_attributes][0][autocomplete_part_id]" size="30" type="text" />
<input data-autocomplete="/items/autocomplete_part_title?locale=en" data-id-element="#autocomplete_5791" id="item_item_parts_attributes_0_autocomplete_part_id" name="item[item_parts_attributes][0][autocomplete_part_id]" size="30" type="text" />

I can have one or more input fields like this.

And I would like to know how could I trigger an event when this field lost focus (blur)

I want to select all the "data-id-element" starting with "#autocomplete_"

$("input#data-id-element^=autocomplete").each().live("blur", function() {
alert('a');
});

something like this, any way?


Try this:

$("input[data-id-element^='#autocomplete']").live("blur", function() {
alert('a');
});

Working example: http://jsfiddle.net/V7N5w/


Found I can perform a loop thro all elements matches doing this:

$("input[data-id-element^='#autocomplete']").live("blur", function(p) {
  p.preventDefault();
  alert('a');
});

Instead of using each() method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜