如何去除引号或从这个(JavaScript)中获取元素

huangapple go评论60阅读模式
英文:

how to remove the quotes or get element from this (javascript)

问题

以下是您要的翻译部分:

"As topic, how can I remove the quote in the picuture below or get the img element from this?
(https://i.stack.imgur.com/kdPAP.png)

I m new to javascript and start making an image slider that can pop up a window while clicked to the image.

I cloned the li object which is clicked, and try to open it in the new window, it do work but how can I get the img only without the li?

Right now i m trying to call the cloned this object with innerHTML, but it shows the img element with quote, is there any way to remove the quote?
the quote that i want to remove

first time ask a question in here, if i violate any rules in the post, i delete the post, sorry for causing any inconvenience."

"这是您的代码的一部分:"

<!DOCTYPE html>
<html>

<head>
    <style>
        .risuto1 {
            max-width: 480px;
            max-height: 270px;
            margin: auto;
            position: relative;
        }

        ul {
            list-style-type: none;
            margin: auto;
            padding: 0;
        }

        .aitemu>img {
            max-width: 100%;
        }

        .aitemu {
            display: none;
            position: relative;
        }

        .aitemu.akutibu {
            display: block;
        }

        .risuto1>.mae,
        .tsugi {
            width: auto;
            height: auto;
            padding: 20px;
            top: 102.6px;
            position: absolute;
            cursor: pointer;
            background-color: red;
        }

        .risuto1>.tsugi {
            left: 431.8px;
        }
    </style>
</head>

<body>
    <script>
        var risuto1 = document.createElement("div");
        risuto1.classList.add("risuto1");
        document.body.appendChild(risuto1);

        var suraidaaitemu = document.createElement("ul");
        suraidaaitemu.classList.add("suraidaaitemu");
        risuto1.appendChild(suraidaaitemu);

        var imejisosurisuto = ["https://pbs.twimg.com/media/CGGc3wKVEAAjmWj?format=jpg&name=medium", "https://pbs.twimg.com/media/EYCXvuzU8AEepqD?format=jpg&name=large", "https://s3-ap-northeast-1.amazonaws.com/cdn.bibi-star.jp/production/imgs/images/000/668/074/original.jpg?1626914998", "https://livedoor.blogimg.jp/rin20064/imgs/7/3/73251146.jpg", "https://www.tbs.co.jp/anime/oregairu/character/img/chara_img_02.jpg"]
        //var imejirisuto=[]

        for (var n = 0; n < imejisosurisuto.length; n++) {
            var imeji = document.createElement("img");
            imeji.src = imejisosurisuto[n];

            var aitemu = document.createElement("li");
            aitemu.classList.add("aitemu");
            suraidaaitemu.appendChild(aitemu);

            aitemu.appendChild(imeji);

            aitemu.onclick=atarashivindou;
        }

        var akutibunasaishonoko = document.querySelector(".suraidaaitemu").firstChild;
        akutibunasaishonoko.classList.add("akutibu");

        var mae = document.createElement("div");
        mae.classList.add("mae");
        mae.innerHTML = "&#10094";
        risuto1.appendChild(mae);

        var tsugi = document.createElement("div");
        tsugi.classList.add("tsugi");
        tsugi.innerHTML = "&#10095";
        risuto1.appendChild(tsugi);

        var tensuu = 0;
        var suraido = document.querySelector(".suraidaaitemu").children;
        var gokeisuraido = suraido.length;

        tsugi.onclick = function () {
            Tsugi("Tsugi");
        }

        mae.onclick = function () {
            Tsugi("Mae");
        }

        function Tsugi(houkou) {
            if (houkou == "Tsugi") {
                tensuu++;
                if (tensuu == gokeisuraido) {
                    tensuu = 0;
                }
            }
            else {
                if (tensuu == 0) {
                    tensuu = gokeisuraido - 1;
                }
                else {
                    tensuu--;
                }

            for (var i = 0; i < suraido.length; i++) {
                suraido[i].classList.remove("akutibu");
            }
            suraido[tensuu].classList.add("akutibu");
        }

        function atarashivindou(){
            var Atarashivindou = window.open("", "_blank", "width: 1000px, max-height: 562.5px");

            var kakudaigazou=document.createElement("div");
            kakudaigazou.classList.add("kakudaigazou");
            Atarashivindou.document.body.appendChild(kakudaigazou);

            var koronaitemu=this.cloneNode(true);
            var koronimeji=koronaitemu.innerHTML;
            kakudaigazou.append(koronimeji);
        }
    </script>
</body>
英文:

As topic, how can I remove the quote in the picuture below or get the img element from this?
(https://i.stack.imgur.com/kdPAP.png)

I m new to javascript and start making an image slider that can pop up a window while clicked to the image.

I cloned the li object which is clicked, and try to open it in the new window, it do work but how can I get the img only without the li?

Right now i m trying to call the cloned this object with innerHTML, but it shows the img element with quote, is there any way to remove the quote?
the quote that i want to remove

first time ask a question in here, if i violate any rules in the post, i delete the post, sorry for causing any inconvenience.

Here is the code

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;
    &lt;style&gt;
        .risuto1 {
            max-width: 480px;
            max-height: 270px;

            margin: auto;
            position: relative;
        }

        ul {
            list-style-type: none;
            margin: auto;
            padding: 0;
        }

        .aitemu&gt;img {
            max-width: 100%;
        }

        .aitemu {
            display: none;
            position: relative;
        }

        .aitemu.akutibu {
            display: block;
        }

        .risuto1&gt;.mae,
        .tsugi {
            width: auto;
            height: auto;

            padding: 20px;
            top: 102.6px;

            position: absolute;

            cursor: pointer;

            background-color: red;
        }

        .risuto1&gt;.tsugi {
            left: 431.8px;
        }
    &lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;script&gt;
        var risuto1 = document.createElement(&quot;div&quot;);
        risuto1.classList.add(&quot;risuto1&quot;);
        document.body.appendChild(risuto1);

        var suraidaaitemu = document.createElement(&quot;ul&quot;);
        suraidaaitemu.classList.add(&quot;suraidaaitemu&quot;);
        risuto1.appendChild(suraidaaitemu);

        var imejisosurisuto = [&quot;https://pbs.twimg.com/media/CGGc3wKVEAAjmWj?format=jpg&amp;name=medium&quot;, &quot;https://pbs.twimg.com/media/EYCXvuzU8AEepqD?format=jpg&amp;name=large&quot;, &quot;https://s3-ap-northeast-1.amazonaws.com/cdn.bibi-star.jp/production/imgs/images/000/668/074/original.jpg?1626914998&quot;, &quot;https://livedoor.blogimg.jp/rin20064/imgs/7/3/73251146.jpg&quot;, &quot;https://www.tbs.co.jp/anime/oregairu/character/img/chara_img_02.jpg&quot;]
        //var imejirisuto=[]

        for (var n = 0; n &lt; imejisosurisuto.length; n++) {
            var imeji = document.createElement(&quot;img&quot;);
            imeji.src = imejisosurisuto[n];

            var aitemu = document.createElement(&quot;li&quot;);
            aitemu.classList.add(&quot;aitemu&quot;);
            suraidaaitemu.appendChild(aitemu);

            aitemu.appendChild(imeji);

            aitemu.onclick=atarashivindou;
        }

        var akutibunasaishonoko = document.querySelector(&quot;.suraidaaitemu&quot;).firstChild;
        akutibunasaishonoko.classList.add(&quot;akutibu&quot;);

        var mae = document.createElement(&quot;div&quot;);
        mae.classList.add(&quot;mae&quot;);
        mae.innerHTML = &quot;&amp;#10094&quot;;
        risuto1.appendChild(mae);

        var tsugi = document.createElement(&quot;div&quot;);
        tsugi.classList.add(&quot;tsugi&quot;);
        tsugi.innerHTML = &quot;&amp;#10095&quot;;
        risuto1.appendChild(tsugi);

        var tensuu = 0;
        var suraido = document.querySelector(&quot;.suraidaaitemu&quot;).children;
        var gokeisuraido = suraido.length;

        tsugi.onclick = function () {
            Tsugi(&quot;Tsugi&quot;);
        }

        mae.onclick = function () {
            Tsugi(&quot;Mae&quot;);
        }

        function Tsugi(houkou) {
            if (houkou == &quot;Tsugi&quot;) {
                tensuu++;
                if (tensuu == gokeisuraido) {
                    tensuu = 0;
                }
            }
            else {
                if (tensuu == 0) {
                    tensuu = gokeisuraido - 1;
                }
                else {
                    tensuu--;
                }
            }

            for (var i = 0; i &lt; suraido.length; i++) {
                suraido[i].classList.remove(&quot;akutibu&quot;);
            }
            suraido[tensuu].classList.add(&quot;akutibu&quot;);
        }

        function atarashivindou(){
            var Atarashivindou = window.open(&quot;&quot;, &quot;_blank&quot;, &quot;width: 1000px, max-height: 562.5px&quot;);

            var kakudaigazou=document.createElement(&quot;div&quot;);
            kakudaigazou.classList.add(&quot;kakudaigazou&quot;);
            Atarashivindou.document.body.appendChild(kakudaigazou);

            var koronaitemu=this.cloneNode(true);
            var koronimeji=koronaitemu.innerHTML;
            kakudaigazou.append(koronimeji);
        }
    &lt;/script&gt;
&lt;/body&gt;

答案1

得分: 0

.innerHTML是一个字符串。你不想追加字符串,而是要追加元素。所以将这部分代码修改为:

var koronimeji = this.querySelector("img").cloneNode();
kakudaigazou.append(koronimeji);
英文:

.innerHTML is a string. You don't want to append a string, but the element. So change this:

        var koronaitemu=this.cloneNode(true);
        var koronimeji=koronaitemu.innerHTML;
        kakudaigazou.append(koronimeji);

...to this:

        var koronimeji=this.querySelector(&quot;img&quot;).cloneNode();
        kakudaigazou.append(koronimeji);

huangapple
  • 本文由 发表于 2023年2月18日 07:30:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490123.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定