.prop(“ disabled”,true)点击对我的元素无效?

时间:2019-12-24 22:41:56

标签: jquery node.js ejs

当对输入元素使用.prop(“ disabled”,true)时,它可以工作,但是该输入元素需要替换为i元素,由于某种原因,它不起作用?知道为什么吗?如有可能,请指出是否有重复的内容?

EJS代码:

                    <div class="bubble sender first">
                        <li class = "display"><%= chats[i].msg %> &nbsp; &nbsp;
                            <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;

    });

1 个答案:

答案 0 :(得分:0)

我建议使用[Y, X, Z]功能。

.off()

查看更多: