Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery追加双重过帐_Jquery_Append_Double - Fatal编程技术网

jQuery追加双重过帐

jQuery追加双重过帐,jquery,append,double,Jquery,Append,Double,我有一个jquery代码,可以发布到php页面,这是对一些结果的回应。 当我点击一个链接并添加数据时,当你多次点击时,数据会翻倍。 它给出了它为什么这样做(我想)的完全合理的解释,但是你对如何防止双附加发生有什么建议吗 代码: 如果要覆盖#txtHint中的数据: jQuery('#txtHint').html(html); 另外,我希望这就是你要问的试着使用 jQuery('#txtHint').html(html); 如果您想保留以前的数据,请像这样尝试 prevHTML=jQuery(

我有一个jquery代码,可以发布到php页面,这是对一些结果的回应。 当我点击一个链接并添加数据时,当你多次点击时,数据会翻倍。 它给出了它为什么这样做(我想)的完全合理的解释,但是你对如何防止双附加发生有什么建议吗

代码:


如果要覆盖#txtHint中的数据:

jQuery('#txtHint').html(html);
另外,我希望这就是你要问的

试着使用

jQuery('#txtHint').html(html);
如果您想保留以前的数据,请像这样尝试

prevHTML=jQuery('#txtHint').html();
newHTML=prevHTML.replace(html,'')+html; // replace previous html if same html comes in
jQuery('#txtHint').html(newHTML);

也许您应该禁用该链接,不允许用户单击该链接,并在附加完成时启用该链接

jQuery(function(){
    jQuery('.link').click(function(){
        var id = jQuery(this).attr('id');
        //diable .link click here
        jQuery.ajax({
          url : "medialib/getpictures.php",
          data: "linkid="+id,
          type : "post",
          success: function(html){
                jQuery('#txtHint').append(html);
                //enable it again here
        }

        });
    return false;
    });
});
或者您可以使用html()函数简单地替换现有内容

像这样,

   success: function(html){
       jQuery('#txtHint').html(html);
   }

给人一种完美的感觉,工作起来很有魅力——非常感谢:)不知道我为什么用append^^
   success: function(html){
       jQuery('#txtHint').html(html);
   }