[英]AJAX atwho listen to all textarea id's
I feel like this is so easy i should kick myself. 我觉得这很容易,我应该踢自己。 I have this coffeescript:
我有这个咖啡脚本:
class @Invitation
@add_atwho = ->
$('#invitation_username_1543').atwho
at: '@'
displayTpl:"<li class='mention-item' data-value='(${image},${name})'><img src=${image}>@${name}</li>",
callbacks: remoteFilter: (query, callback) ->
if (query.length < 1)
return false
else
$.getJSON '/mentionsy', { q: query }, (data) ->
callback data
jQuery ->
Invitation.add_atwho()
And instead of listening to JUST #invitation_username_1543
i want to replace that 1543 with any id number on my page. 而且,我不想只听
#invitation_username_1543
而是将其1543替换为页面上的任何ID号。 I've got this partial modal rendering as well. 我也有这个局部模态渲染。 The line in question that the coffeescript is listening to is the one with textarea id = "invitation_username_+#{x.id}".
有问题的咖啡脚本正在收听的行是textarea id =“ invitation_username _ +#{x.id}”的行。 it works great for the modal with 1543 id being passed in to it, but nothing else!
它非常适合将1543 id传递给它的模态,但是没有别的!
<div class="modal fade" id="invite-<%= x.id %>" tabindex="-1" role="dialog" aria-labelledby="pirateinviteLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="inviteLabel">Invite a Friend!</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Text Text Text<br /><br />
<%= form_for @invitations, :url => invitations_path, :method => 'create', remote: true do |b| %>
<div class="form-group"><center>
<b><%= b.label :username, 'Invite a friend by username:' %></b></center>
<%= b.text_area :username, id: "invitation_username_#{+ x.id}", rows: 1, role: "textarea", class: 'form-control', required: true, placeholder: "@user1 @user2" %>
<%= b.hidden_field :event_id, :value => x.id %>
</div>
<div class="text-center">
<%= b.submit 'Send an Invite!', class: 'btn btn-primary btn-sm align-self-center' %>
<% end %></div>
</div>
</div>
</div>
</div>
You can use attribute begins with selector [attr^=value]
to select elements where attr
attribute begins with ^=
attribute value
您可以使用以选择器
[attr^=value]
开头的属性来选择attr
属性以^=
属性value
开头的元素
$("textarea[id^=invitation_username_]")
or 要么
document.querySelectorAll("textarea[id^=invitation_username_]")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.