Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
can';t使用jquery追加多行html_Jquery_Html - Fatal编程技术网

can';t使用jquery追加多行html

can';t使用jquery追加多行html,jquery,html,Jquery,Html,我正试图使用jquery将多行HTML代码附加到div中,但它总是给我错误“意外标记非法” 下面是我试图附加的一行: $('.irbiswindow').append('<table class="ts"><tr><th class="ts-yw4l" rowspan="3"><img src="img/previews/3_1_1.jpg" class="previewing">

我正试图使用jquery将多行HTML代码附加到div中,但它总是给我错误“意外标记非法”

下面是我试图附加的一行:

$('.irbiswindow').append('<table class="ts"><tr><th class="ts-yw4l" rowspan="3"><img src="img/previews/3_1_1.jpg" class="previewing">
                                        <img src="img/previews/3_1_2.jpg" class="previewing"><img src="img/previews/3_1_3.jpg" class="previewing"><img src="img/previews/3_1_4.jpg" class="previewing"><img src="img/previews/3_1_5.jpg" class="previewing"></th>
                                        <th class="ts-yw4l"><p class="comment">Rare and gorgeous "irbis" snow leopards observe the surroundings ready to hunt.</p><p class="comment">3Ds Max, Photoshop, Vray, Zbrush</p></th></tr><tr><td class="ts-yw4l"></td></tr><tr>
                                        <td class="ts-yw4l"></td></tr></table>');
$('.irbiswindow')。追加('

稀有而华丽的“irbis”雪豹观察周围环境,准备捕猎。

3Ds Max、Photoshop、Vray、Zbrush

');
尝试使用此技巧进行多行连接
'text'+换行符'text'

$('.irbiswindow').append('<table class="ts"><tr><th class="ts-yw4l" rowspan="3"><img src="img/previews/3_1_1.jpg" class="previewing">' +
    '<img src="img/previews/3_1_2.jpg" class="previewing"><img src="img/previews/3_1_3.jpg" class="previewing"><img src="img/previews/3_1_4.jpg" class="previewing"><img src="img/previews/3_1_5.jpg" class="previewing"></th>' +
    '<th class="ts-yw4l"><p class="comment">Rare and gorgeous "irbis" snow leopards observe the surroundings ready to hunt.</p><p class="comment">3Ds Max, Photoshop, Vray, Zbrush</p></th></tr><tr><td class="ts-yw4l"></td></tr><tr>' +
    '<td class="ts-yw4l"></td></tr></table>');
$('.irbiswindow')。追加(''+
'' +
“

稀有而华丽的“irbis”雪豹观察周围的环境,准备捕猎。

3Ds Max、Photoshop、Vray、Zbrush

”+ '');
尝试使用此技巧进行多行连接
'text'+换行符'text'

$('.irbiswindow').append('<table class="ts"><tr><th class="ts-yw4l" rowspan="3"><img src="img/previews/3_1_1.jpg" class="previewing">' +
    '<img src="img/previews/3_1_2.jpg" class="previewing"><img src="img/previews/3_1_3.jpg" class="previewing"><img src="img/previews/3_1_4.jpg" class="previewing"><img src="img/previews/3_1_5.jpg" class="previewing"></th>' +
    '<th class="ts-yw4l"><p class="comment">Rare and gorgeous "irbis" snow leopards observe the surroundings ready to hunt.</p><p class="comment">3Ds Max, Photoshop, Vray, Zbrush</p></th></tr><tr><td class="ts-yw4l"></td></tr><tr>' +
    '<td class="ts-yw4l"></td></tr></table>');
$('.irbiswindow')。追加(''+
'' +
“

稀有而华丽的“irbis”雪豹观察周围的环境,准备捕猎。

3Ds Max、Photoshop、Vray、Zbrush

”+ '');
您可以将html存储在js变量中,如下所示:

var html;
html += '<table class="ts">';
html += '    <tr>';
html += '      <td>';
...
html += '      </td>';
html += '    </tr>';
html += '</table>';

$('.screencontainer').delay(0).animate({height:"2560px",width:"1000px"},0, function(){$('.irbiswindow').append(html)});
var-html;
html+='';
html+='';
html+='';
...
html+='';
html+='';
html+='';
$('.screencainer').delay(0).animate({height:“2560px”,width:“1000px”},0,function(){$('.irbiswindow').append(html)});

您可以将html存储在js变量中,如下所示:

var html;
html += '<table class="ts">';
html += '    <tr>';
html += '      <td>';
...
html += '      </td>';
html += '    </tr>';
html += '</table>';

$('.screencontainer').delay(0).animate({height:"2560px",width:"1000px"},0, function(){$('.irbiswindow').append(html)});
var-html;
html+='';
html+='';
html+='';
...
html+='';
html+='';
html+='';
$('.screencainer').delay(0).animate({height:“2560px”,width:“1000px”},0,function(){$('.irbiswindow').append(html)});

最好将静态HTML放在实际HTML中,然后克隆内容以附加它:

$('.irbiswindow').append($(“#tableToClone”).clone()

稀有而华丽的“irbis”雪豹观察周围的环境,准备捕猎

3Ds Max、Photoshop、Vray、Zbrush


最好将静态HTML放在实际HTML中,然后克隆内容以附加它:

$('.irbiswindow').append($(“#tableToClone”).clone()

稀有而华丽的“irbis”雪豹观察周围的环境,准备捕猎

3Ds Max、Photoshop、Vray、Zbrush


默认情况下,包含换行符的HTML代码不能直接与
附加/prepend
一起使用。但幸运的是,目前有以下有效方法:

  • 使用“+”连接HTML代码段

  • 使用“\”来转义

  • 使用“`”(回勾,),不需要任何额外的操作。 ES2015/ES6()支持此方法

  • 添加一个隐藏的
    标记
    ,该标记包含与所需HTML代码相同的HTML代码,例如

    ,然后使用
    .append($('foo').HTML())

    现在将一些使用场景发布到上面提到的
    前三种方法中(只需在
    Chrome
    浏览器的控制台中运行它们即可):


  • 我们可以清楚地看到它们之间的差异。

    默认情况下,包含换行符的HTML代码不能直接与
    append/prepend
    一起使用。但幸运的是,目前有以下有效方法:

  • 使用“+”连接HTML代码段

  • 使用“\”来转义

  • 使用“`”(回勾,),不需要任何额外的操作。 ES2015/ES6()支持此方法

  • 添加一个隐藏的
    标记
    ,该标记包含与所需HTML代码相同的HTML代码,例如

    ,然后使用
    .append($('foo').HTML())

    现在将一些使用场景发布到上面提到的
    前三种方法中(只需在
    Chrome
    浏览器的控制台中运行它们即可):


  • 我们可以清楚地看到它们的差异。

    我需要为许多元素更改这些img路径。假设我有一个图库,我需要为4_1_1.jpg 5_1_1.jpg等一遍又一遍地写,并且每次都要更改标题。所以我不知道我是否能以这种方式将所有变量存储在一个全局变量中;我需要改变很多元素的img路径。假设我有一个图库,我需要为4_1_1.jpg 5_1_1.jpg等一遍又一遍地写,并且每次都要更改标题。所以我不知道我是否能以这种方式将所有变量存储在一个全局变量中;看起来不错,但是每次我克隆它时,有没有办法改变这些数字呢?我有不同的图像,如4_1_1.jpg、5_1_1.jpg等,还有不同的标题。如果我使用静态html,我将无法每次都更改它。是的,当然。这就是jQuery的强大功能。只需给每个img一个不同的ID,然后更改它的src属性。添加文本真的不是这样做的,你知道为什么要克隆()吗;可以克隆8次而不是一次吗?我使用了您的代码,它一个接一个地创建了8个tableToClone元素。它默认克隆8次吗?不,它应该只克隆一次。我必须查看您的代码/html才能了解问题所在。听起来好像有多个表具有相同的ID(无论如何你都不应该这样做),哦,我实际上尝试使用.html而不是.append,它删除了所有这些克隆。不知道为什么,但我做了。看起来很好,但是每次我克隆它时,有没有办法改变这些数字?我有不同的图片,比如4_1_1.jpg,5_1