簡體   English   中英

按下后停止按鈕動作

[英]Stop button action after press it

我有一個JS函數,可加載某個答案的注釋。 這個想法是調用一個API函數並返回注釋。 問題在於,每當我按下按鈕時,它都會加載評論,這些評論完全相同。 我希望您在按評論后無法加載更多評論。 我雖然可以使用stopPropagation來解決問題,但是什么也沒發生。

調用后按“評論”按鈕時是否可以關閉我的#showarea

<div class="post-button clearfix">
                <div class="post-button clearfix">
                    <button class="btn icon-chat show-textarea" title="Add a comment on this answer" type="button" data-answer="{$answer['publicationid']}">Comment</button>
                    <div class="textarea">
                        {include file="comment_form.tpl"}
                    </div>
                </div>
            </div>

comment_form.tpl

$('.comment-form').hide();
var commentsFetched = false;

$("body").on("click", ".show-textarea", function(){
    if (commentsFetched) { // check the flag
        return;
    }
    $.getJSON("/controller/api/comments/comment.php", {
        answerid : answerid
    }, function (data) {
        commentsFetched = true;
        $.each(data, function(i, comment) {
            console.log(comment);
            $('.comment-form').append('<article class="tweet-data">' +
                '<div class="comment-items">' +
                '<div class="qa-c-list-item  hentry comment" id="c3574">' +
                '<div class="asker-avatar">' +
                '<a>' +
                '<img width="40" height="40" src="' +
                comment.user_photo +
                '"></a>' +
                '</div>' +
                '<div class="qa-c-wrap">' +
                '<div class="post-button">' +
                '<button name="" onclick="" class="btn icon-flag" title="Flag this comment as spam or inappropriate" type="submit">flag</button>' +
                '<button name="" class="btn icon-answers" title="Reply to this comment" type="submit">reply</button>' +
                '</div>' +
                '<span class="qa-c-item-meta">' +
                'commented' +
                ' 1 day' +
                ' ago' +
                ' by ' +
                '<a style="display: inline" href="" class="qa-user-link url nickname">' +
                comment.username +
                '</a> ' +
                '<span class="qa-c-item-who-points"> ' +
                '<span class="qa-c-item-who-points-pad">(</span><span class="qa-c-item-who-points-data">140</span><span class="qa-c-item-who-points-pad"> points)</span> ' +
                '</span> ' +
                '</span> ' +
                '</span> ' +
                '<div class="qa-c-item-content" style="color: #2d2727; font-size: 13px"> ' +
                '<a name="3574"></a><div class="entry-content">' +
                comment.body +
                '</div> ' +
                '</div> ' +
                '</div> <!-- END qa-c-item --> ' +
                '</div> ' +
                '</div>');
        });
    });

    $('.comment-form').show();
});

$("body").on("click", ".textarea-ok, .textarea-cancel", function(){
    commentsFetched = false;
    $('.comment-form').hide();
});

設置一個標志來知道您是否已獲取評論。

var commentsFetched = false;
$("#showarea").click(function() {
    if (commentsFetched) { // check the flag
       return;
    }

    $.getJSON("/controller/api/comments/comment.php", {
        answerid : answerid
    }, function (data) {
        commentsFetched = true; // set the flag
        $.each(data, function(i, comment) {
    ...

您可能應該禁用該按鈕,以便為用戶提供直觀的指示,表明無法加載更多評論

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM