Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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
Javascript 在js函数中插入一个div并将其删除_Javascript_Php_Jquery - Fatal编程技术网

Javascript 在js函数中插入一个div并将其删除

Javascript 在js函数中插入一个div并将其删除,javascript,php,jquery,Javascript,Php,Jquery,我这里有一个脚本,需要一些手工操作。开发人员不提供修改支持,我也不完全精通JS,所以我需要一些帮助。基本上,下面的脚本显示了一个woocommerce产品图像,还有一个预加载功能。我需要在preload\u img.onload=函数之前插入一个名为.temp image的div,并在preload\u img.onload=函数中删除该div if ($(img).length > 0) { img.data('tm-current-image', false); var

我这里有一个脚本,需要一些手工操作。开发人员不提供修改支持,我也不完全精通JS,所以我需要一些帮助。基本上,下面的脚本显示了一个woocommerce产品图像,还有一个预加载功能。我需要在preload\u img.onload=函数之前插入一个名为.temp image的div,并在preload\u img.onload=函数中删除该div

if ($(img).length > 0) {
    img.data('tm-current-image', false);
    var a = img.closest("a");
    var a_href_original = a.attr('href');
    main_product.on('tm_change_product_image', function(e) {
        var tm_current_image_element_id = e.element.attr('name'),
            $main_product = e.main_product;

        var clone_image = img.tm_clone(),
            preload_img = new Image();

        preload_img.onload = function() {
            $main_product.find('#' + tm_current_image_element_id + '_tmimage').remove();

            $main_product.find('.tm-clone-product-image').hide();

            clone_image.prop('src', preload_img.src).hide();

            img.hide().after(clone_image);

            clone_image.show();

            if (is_iosSlider) {

                setTimeout(function() {

                    is_iosSlider_element.iosSlider('update');

                }, 150);

            }

        };

        clone_image

            .attr('id', tm_current_image_element_id + '_tmimage')

        .addClass('tm-clone-product-image').hide(); //.show();

        preload_img.src = e.src;

        a.attr('href', e.src);

        img.data('tm-current-image', tm_current_image_element_id);

        if (is_yith_wcmg) {

            yith_wcmg.yith_magnifier('destroy');

            yith_wcmg.yith_magnifier(yith_magnifier_options);

        }

    });
}

我不清楚你的问题,但是你可以用这个来添加div,假设你想在这是div之后添加div,并且你想在这之后添加div

   <script type="text/javascript">
      $(".test").append("<div id='specificdiv'>hello world</div>");
  </script>

$(“.test”).append(“hello world”);


$(“您好,这是添加的div”).appendTo(“.test”);


$(“”)。attr('id','specificdiv')。appendTo('body');
并将其移除

<script type="text/javascript">
        $( "#specificdiv" ).remove(); 
    </script>

$(“#specificdiv”).remove();


$(“#specificdiv”).empty();
    <script type="text/javascript">
        $("<div></div>").attr('id','specificdiv').appendTo('body'); 
    </script>
<script type="text/javascript">
        $( "#specificdiv" ).remove(); 
    </script>
<script type="text/javascript">
        $( "#specificdiv" ).empty(); 
    </script>