当对输入元素使用.prop(“ disabled”,true)时,它可以工作,但是该输入元素需要替换为i元素,由于某种原因,它不起作用?知道为什么吗?如有可能,请指出是否有重复的内容?
EJS代码:
<div class="bubble sender first">
<li class = "display"><%= chats[i].msg %>
<i class="fas fa-heart" aria-hidden="true"></i>
<input type="hidden" id = "changeit" class = "likebutton" value = "Likes: (<%=chats[i].likes%>)" >
<input type="hidden" class = "hiddentag" value="<%=chats[i].msg%>"> <!-- needed to get the message that was liked-->
<input type="hidden" class = "hiddendatetag" value="<%=chats[i].date%>"> <!-- needed to filter messages that are the same-->
</li>
<br>
<span>Sent: <%= chats[i].date%> </span>
</div>
jQuery代码:
$('i').on('click', function(){ // hit like
var data = $(this).next('input').val(); // get value of likes
var msgdata = $(this).next().next('input').val(); //gets the message that was selected
var datedata = $(this).next().next().next('input').val(); // get the date val
$(this).toggleClass('clicked');
$(this).prop("disabled", true); // BUG: INFITINITE LIKES ON A POST FIX THIS!!
var likedmsg = {msg: msgdata, likes: '-1', date: datedata}; //dictates a message was liked so find it in database and update it
$.ajax({ //do something with the data via front-end framework, so we can update in reall time
type: 'GET',
url: '/',
success: function(err){
$.ajax({
type: 'POST',
url: '/',
data: likedmsg,
success: function(data){
//do something with the data via front-end framework, so we can update in reall time
console.log("Success. Like submitted");
}
});
return false;
console.log('success!');
}
});
return false;
});