开发者

how to catch multiple ids?

My button is dynamic. So, It has multiple ids say view-123, view-324, view-423 etc. On button click I am calling a jQuery file having:

 $(document).ready(function() {
        $('tr[id^view-]').click(function() {
            alert(this.id)
        });
    });

To catch the id, But it is not working?

 $('.view').click(function() {
        alert(this.id)
   });

This is returning nothing. html is:

{% for item in users %}

          <tr class="row">
            <td class="number">{% if item.phone_number %}{{ item.phone_number }}{% else %}-{% endif %}</td>

            <td><input type="submit" class="view" name="view-{{ item开发者_如何学JAVA.phone_number }}" value="View"></td>

          </tr>
{% endfor %}


Try using ^= rather than just ^:

 $('tr[id^="view-"]')

Also, this would be nicer if you used a class for all the applicable elements.


If you want to match multiple elements at once, you're better off using a class rather than multiple IDs.


Why don't you add class to button

$(document).ready(function() {
$('.class').click(function() {
    alert($(this).attr("id"));
});

i think this is easy way .. Thanks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜