Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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标记附加到字段变量是错误的吗 html+='ID:'+one+''; html+=“说明:”; html+=''; html+=“标题:”; html+=''; html+=“结束日期:”; html+=''//我正在覆盖日历图像的默认宽度 html+='';_Html - Fatal编程技术网

有人能解释为什么将html标记附加到字段变量是错误的吗 html+='ID:'+one+''; html+=“说明:”; html+=''; html+=“标题:”; html+=''; html+=“结束日期:”; html+=''//我正在覆盖日历图像的默认宽度 html+='';

有人能解释为什么将html标记附加到字段变量是错误的吗 html+='ID:'+one+''; html+=“说明:”; html+=''; html+=“标题:”; html+=''; html+=“结束日期:”; html+=''//我正在覆盖日历图像的默认宽度 html+='';,html,Html,我可以想到三个原因: 像“+”这样的字符串连接器操作数使其更难读取 缩进比较困难,因为缩进字段以模拟格式正确的html代码段很难 显示逻辑与业务应用程序逻辑紧密地混合在一起,使得关注点难以多样化 你列出了三个好的理由,并且在前三名中。试图将两者混用会导致代码难看、难以阅读、难以维护等 不过,我直到最近才想到的另一件事是,一些编辑器(如Netbeans)会在HTML被破坏时告诉您。忘记关闭标记、错误的值等。我正在使用PHP进行工作,我养成了这样做的习惯: html += '<tr st

我可以想到三个原因:

  • 像“+”这样的字符串连接器操作数使其更难读取
  • 缩进比较困难,因为缩进字段以模拟格式正确的html代码段很难
  • 显示逻辑与业务应用程序逻辑紧密地混合在一起,使得关注点难以多样化

  • 你列出了三个好的理由,并且在前三名中。试图将两者混用会导致代码难看、难以阅读、难以维护等

    不过,我直到最近才想到的另一件事是,一些编辑器(如Netbeans)会在HTML被破坏时告诉您。忘记关闭标记、错误的值等。我正在使用PHP进行工作,我养成了这样做的习惯:

       html += '<tr style="display:none;"><td class="leftval">ID:</td><td><span id="' + _uniqueId + '-id">' + one + '</span></td></tr>';
        html += '<tr><td class="leftval"><label for="' + _uniqueId + '-itemdesc" title="This is the descriptive text that will actually appear in the email.">Description: </label></td>';
        html += '<td><input value="' + four + '" class="CDinput" name="itemdesc" id="' + _uniqueId + '-itemdesc" type="text"></td></tr>';
        html += '<tr><td class="leftval"><label for="' + _uniqueId + '-title" title="This is the title text that is used in the email.  The text usually is used as the anchor text of a link.">Title: </label></td>';
        html += '<td><input value="' + five + '" class="CDinput" name="title" id="' + _uniqueId + '-title" type="text"></td></tr>';
        html += '<tr><td class="leftval"><label style="color:#f16d44;" for="' + _uniqueId + '-enddate" title="This is the expiration of the offer.  The formating here is arbitrary and does not impact how the end date would look in the actual template.">End Date: </label></td>';
        html += '<td><input style="width:230px" value="' + six + '" class="CDinput" name="enddate" id="' + _uniqueId + '-itemenddate" type="text">';//I'm overriding the default width for the calendar image
        html += '<img style="cursor:pointer;" class="CDdate" id="' + _uniqueId + '-dateselector"src="/images/Calendar_hyperlink.png"></td></tr>';
    
    <li>
        <span class='name'><?php echo _TAG_INDEX ?>:</span>
        <span class='value'><?php echo $get_zone_array['DB_ID'] ?></span>
    </li>
    
  • :
  • 像这样使用它,如果我忘了关闭标签,比如我忘了在某处关闭
    ,它会为我指出它,这样我就可以进去修复它。但是,如果我将HTML放入一个变量中,或者直接回显它,如下所示:

       html += '<tr style="display:none;"><td class="leftval">ID:</td><td><span id="' + _uniqueId + '-id">' + one + '</span></td></tr>';
        html += '<tr><td class="leftval"><label for="' + _uniqueId + '-itemdesc" title="This is the descriptive text that will actually appear in the email.">Description: </label></td>';
        html += '<td><input value="' + four + '" class="CDinput" name="itemdesc" id="' + _uniqueId + '-itemdesc" type="text"></td></tr>';
        html += '<tr><td class="leftval"><label for="' + _uniqueId + '-title" title="This is the title text that is used in the email.  The text usually is used as the anchor text of a link.">Title: </label></td>';
        html += '<td><input value="' + five + '" class="CDinput" name="title" id="' + _uniqueId + '-title" type="text"></td></tr>';
        html += '<tr><td class="leftval"><label style="color:#f16d44;" for="' + _uniqueId + '-enddate" title="This is the expiration of the offer.  The formating here is arbitrary and does not impact how the end date would look in the actual template.">End Date: </label></td>';
        html += '<td><input style="width:230px" value="' + six + '" class="CDinput" name="enddate" id="' + _uniqueId + '-itemenddate" type="text">';//I'm overriding the default width for the calendar image
        html += '<img style="cursor:pointer;" class="CDdate" id="' + _uniqueId + '-dateselector"src="/images/Calendar_hyperlink.png"></td></tr>';
    
    <li>
        <span class='name'><?php echo _TAG_INDEX ?>:</span>
        <span class='value'><?php echo $get_zone_array['DB_ID'] ?></span>
    </li>
    
    $html=“
  • ”。\u TAG\u INDEX.:“//注意缺少/in . “.$get\u zone\u数组['DB\u ID']”” . “
  • ”; echo$html;
    这样编辑器就不会进行任何HTML检查,使得查找那些令人讨厌的xHTML小错误变得更加困难。

    原因如下:

  • 它的屁股很丑
  • 很慢。(Java中的
    +=
    操作符不快。有时可以接受,但肯定不快,因为它必须进行大量对象创建和缓冲区复制。)
  • 通过未正确引用字符串很容易引入XSS漏洞
  • 它太死板了;更改布局上的任何内容,都必须更改所有代码

  • 改用模板库。所以更容易找到正确的答案。

    Donal,你能举一个4的例子吗。如果需要更改布局,您不需要更改代码吗?@ilupper:如果您从外部文件中提取布局,则不需要更改代码。将业务逻辑(将数据放入数据库,然后再将其取出)与显示分离可以让生活变得简单得多,特别是因为这意味着您可以使逻辑更加健壮,而不用担心弄乱时髦的显示,反之亦然。这只是常识。(我过去的做法是以纯XML的形式交付数据,并使用XSLT/CSS使其看起来很好。还有其他方法)第二种方法,实际上是javascript。