我正在定義一個on'submit'事件,如下所示:HTML代碼是:<div class="messages"> <ul> <li class="sent"> <img src="/img/person1.png" alt="" /> <p>How the hell am I supposed to get a jury to believe you when I am not even sure that I do?!</p> </li> <li class="replies"> <img src="/img/botimg.png" alt="" /> <p>When you're backed against the wall, break the god damn thing down.</p> </li> <li class="replies"> <img src="/img/botimg.png" alt="" /> <p>Excuses don't win championships.</p> </li> <li class="sent"> <img src="/img/person1.png" alt="" /> <p>Oh yeah, did Michael Jordan tell you that?</p> </li> <li class="replies"> <img src="/img/botimg.png" alt="" /> <p>No, I told him that.</p> </li> </ul> </div> <div class="message-input"> <div class="wrap"> <input type="text" placeholder="Write your message..." /> <i class="fa fa-paperclip attachment" aria-hidden="true"></i> <button class="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i></button> </div> </div>輔助功能:function newMessage() { console.log("Inside newMessage"); message = $(".message-input input").val(); if($.trim(message) == '') { return false; } $('<li class="sent"><img src="/img/person1.png" alt="" /><p>' + message + '</p></li>').appendTo($('.messages ul')); $('.message-input input').val(null); $(".messages").animate({ scrollTop: $(document).height() }, "fast");};提交點擊功能是:$('.submit').click(function() { newMessage();});現在,每當我單擊“提交”按鈕時,“ Inside newMessage”消息就會不斷在JavaScript控制臺中記錄。
為什么我的JavaScript顯然陷入了無限循環?
郎朗坤
2021-04-14 13:15:30