Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.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/3/html/91.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
如何将html代码放入jQuery或JavaScript的append中?_Javascript_Jquery_Angularjs - Fatal编程技术网

如何将html代码放入jQuery或JavaScript的append中?

如何将html代码放入jQuery或JavaScript的append中?,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,如何在jquery的append中放入html,在网页中追加Div $('.oo').append( <div style="width:100%; min-height:35px; max-height:auto; margin-top:10px;"> <div style="height:auto; margin:2px 2px 2px 16px;">

如何在jquery的append中放入html,在网页中追加Div

              $('.oo').append(
               <div style="width:100%; min-height:35px; max-height:auto; margin-top:10px;">
               <div style="height:auto; margin:2px 2px 2px 16px;">
              <img src="image/xprin_load2_loader.gif" style="float:left; height:35px; width:35px; border-radius:5%;"/>
                 </div>
                 <div style="height:auto; margin: 5px 5px 5px 55px;  text-align:left; box-shadow: 3px 0px 0px #4080ff;">
                <b>: </b>
                <span style="margin:2px 2px;"></span>
               </div>
               </div>
             ); 
$('.oo')。追加(
: 
); 
像这样做

$('.oo').append(
'<div style="width:100%; min-height:35px; max-height:auto'
 +'; margin-top:10px;">
               <div style="height:auto; margin:2p'
 +'x 2px 2px 16px;">
              <img src="image/xprin_load2_loader.gif'
 +'" style="float:left; height:35px; width:35px; border-radius:5%;"/>
   '
 +'              </div>
                 <div style="height:auto; margin:'
 +' 5px 5px 5px 55px;  text-align:left; box-shadow: 3px 0px 0px #4080ff;"'
 +'>
                <b>: </b>
                <span style="margin:2px 2p'
 +'x;"></span>
               </div>
               </div>');
$('.oo')。追加(
'
'
+'              
: 
');

它将起作用。

您只需在要附加的html周围添加引号即可

  $('.oo').append(
    ' <div style="width:100%; min-height:35px; max-height:auto; margin-top:10px;">' +
    +' <div style="height:auto; margin:2px 2px 2px 16px;">' + ' <img src="image/xprin_load2_loader.gif" style="float:left; height:35px; width:35px; border-radius:5%;"/>' + '</div>' + '<div style="height:auto; margin: 5px 5px 5px 55px;  text-align:left; box-shadow: 3px 0px 0px #4080ff;">' + '<b>: </b>' + '<span style="margin:2px 2px;"></span>' + '</div>' + '</div>'
  );
$('.oo')。追加(
' ' +
+' ' + ' ' + '' + '' + ': ' + '' + '' + ''
);

在要添加的html周围添加引号RTD:还建议您使用样式表,而不是使用内联样式来扩展html。除了按照Rory的建议使用样式表和类之外,我还强烈建议您从硬连接的html转移到任何形式的模板系统。作为模板编写和维护HTML要容易得多。