我有這樣的代碼.attr()在屬性選擇一個變量不行
<div class="field">
<label>Title</label>
<input id="post-titie" type="text">
</div>
<div class="ui olive message" for-field="post-title" hidden>
<div class="header">About Title</div>
<ul class="list">
<li>Visitors can see your title even if they're not logged in.</li>
<li>The title is public.</li>
</ul>
</div>
我想要做的就是當<input>
或<textarea>
集中,顯示的信息與DIV .message
類。
我將$(this).attr('id')
作爲變量(例如,post-title
),並通過.find('div[for-field="'+forwhom+'"]')
找到它。這不起作用。
但是,如果我將var forwhom
從$(this).attr('id')
(jQ選擇器)替換爲絕對值,如post-title
,它確實有效。
很奇怪!根據jQuery文檔,.attr()
方法返回的字符串不是對象。
什麼問題?
只需試試這個'$(':input')'因爲:input是一個jquery擴展 – gurvinder372
當我嘗試它時它工作正常:http://jsbin.com/pusoyej/1/edit?html, js,輸出 – Quentin