javascript - 将html添加到div而不替换其中的当前内容

标签 javascript jquery dhtml

我正在尝试将 dhtml 添加到 ID 为 upload_results 的 div。这应该可以在不替换 div 中的当前内容的情况下工作。

代码:(有趣的部分在底部)

<script language="JavaScript">
 function do_show() {
      $("#webcamContainer").fadeIn('');
  }

  webcam.set_hook( 'onComplete', 'my_completion_handler' );

  function do_upload() {
       upload to server
      document.getElementById('upload_results').innerHTML = '<div>Uploading...</div>';
      webcam.upload();
  }

  function my_completion_handler(msg) {
       extract URL out of PHP output
      if (msg.match(/(http\:\/\/\S+)/)) {
          var image_url = RegExp.$1;
           show JPEG image in page
          $("#upload_results").fadeIn('');
          //document.getElementById('upload_results').innerHTML = '<a target="_blank" href="'+image_url+'"><img style="border:#ccc 5px solid;" src="'+image_url+'" width="100px"></a>';// I think here should be something changed
    $('#upload_results').append('<a target="_blank" href="'+image_url+'"><img style="border:#ccc 5px solid;" src="'+image_url+'" width="100px"></a>');      
           reset camera for another shot
          webcam.reset();
      }
      else alert("PHP Error: " + msg);
  }
 </script>


 <div id="upload_results" class="video_header" style="display:none;"></div><!--add data here , without replace current content in div-->

最佳答案

关于javascript - 将html添加到div而不替换其中的当前内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14298989/

相关文章:

javascript - 处理旅行动画

javascript - 正则表达式 : How can I find form fields named with specific character sequence in a form using javascript?

asp.net - 是否有像 contentplaceholder 这样的控件在 asp.net 中用于纯 html

javascript - 谷歌图表 - 每个图表都有隐藏线的多个折线图数据表

javascript - 如何使用 ES6 语法导入 pg-promise?

javascript - 在移动状态下调整 Bootstrap 轮播中的图像高度

jquery - WCF GET URL 长度限制问题 : Bad Request - Invalid URL

javascript - 使用 AngularJS 将 date() 保存在 JSON 中

javascript - 我如何在 Jquery 中将 delay() 与 show() 和 hide() 一起使用

javascript - Jquery:如何禁用 <TR> 中的同级下拉值