2016-04-10 20 views
0

在我的項目中,我希望在提交評論後數據得到更新。 這是我的更新功能。jquery更新數據點擊將綁定兩次

function renderContent(ret) { 
    $(".authorWrap").on('click',function() { 
     xqBridge.redirect({ 
      type: "push", 
      url: "users", 
      data: ret["owner"] 
     }) 
    }); 
} 

點擊將綁定兩次。

你能給點建議嗎?

謝謝。

+0

嘗試在你的函數中添加「event.stopPropagation()」爲「on」 –

+0

你是否多次調用'renderContent'? – CBroe

+0

看來你正在綁定更新函數調用的click事件。應該首先附加事件,然後點擊更新功能時觸發。你正在做的是在更新功能上附加一個事件,該事件應該提前附加,可能會在頁面加載。 – jeetaz

回答

0
function renderContent(ret) { 
$(".authorWrap").on('click',function() { 
    xqBridge.redirect({ 
     type: "push", 
     url: "users", 
     data: ret["owner"] 
    }) 
});return false;} 
0

你是否運行renderContent函數兩次?

更高級的方式是使用委託。例如, 。

$(document).on('click','.authorWrap',function(e,ret) { 
     xqBridge.redirect({ 
     type: "push", 
     url: "users", 
     data: ret["owner"] 
    }) 
    });