简体   繁体   English

AJAX atw谁收听所有textarea id的

[英]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">&times;</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.

相关问题 是否可以监听所有 Ajax 调用? - Is it possible to listen all Ajax calls? Django jquery与ajax。 如何使jquery监听生成的表单的id - Django jquery with ajax. How to make jquery to listen id's of generated forms 在内容脚本中侦听AJAX响应何时更改文本区域值 - Listen in Content Script for when AJAX response changes textarea val 在按键上检索 textarea 的 id - Retrieve textarea's id on keypress 在所有文本区域(包括通过ajax加载的文本区域)之上自动初始化RTF编辑器 - Automatically initialize rich text editor on top of all textarea's, including ones that are loaded via ajax 抓取表单中的所有ID并将它们放入数组中(input,select和textarea) - Grabbing all ID's within a form and putting them in an array ( input, select & textarea ) 监视/监听Ajax readyState - Monitor / listen for Ajax readyState 如何使用 Web Speech API 以一种可以听到 textarea 行的单词的方式,每行都以延迟的方式? - How does one use the Web Speech API in a way that one can listen to the words of a textarea's lines, each line in a delayed way? 在ajax结果中循环并用id替换所有元素 - Loop in ajax results and replace all elements with id 将嵌套列表放入文本区域不会关闭全部 <ul> s - Getting a nested list into a textarea it is not closing all <ul>s
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM