[英]jQuery only works by selecting the ID, not the class
我試圖做一個事件監聽器,在我的例子中是用“ keyup”來計算輸入的元素。
當我將消息框與其ID鏈接起來時,一切正常,如下所示:
$("#message-box-1").on("keyup", function() {...
但是當我鏈接課程時,就像這樣:
$(".message-box").on("keyup", function() {...
計數器不再工作了。
在不得不使用ID而不是類之前,我遇到了類似的問題,因為否則該功能將無法正常工作...
你有兩節課
<textarea style="resize:none" cols="40" rows="5" class="form-control" class="message-box" id="message-box-1" title="Please enter a message" required="required" placeholder="Your message here"></textarea>
請刪除,因為jquery將忽略具有相同名稱的第二個屬性或與相同的class屬性合並
<textarea style="resize:none" cols="40" rows="5" class="form-control message-box" id="message-box-1" title="Please enter a message" required="required" placeholder="Your message here"></textarea>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.