Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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
如何使用Jquery创建表_Jquery_Html_Css - Fatal编程技术网

如何使用Jquery创建表

如何使用Jquery创建表,jquery,html,css,Jquery,Html,Css,我想在发生错误时发出错误消息 HTML: 我希望将此表插入到div中: <table id="error" style="width:900px;border-top: 1px Solid #B7B7B7;border-right: 1px Solid #B7B7B7; border-left: 1px Solid #B7B7B7;border-collapse: collapse;background-color:#E7E7E7;height:auto;"> <tr

我想在发生错误时发出错误消息

HTML:

我希望将此表插入到div中:

<table id="error" style="width:900px;border-top: 1px Solid #B7B7B7;border-right: 1px Solid #B7B7B7;
   border-left: 1px Solid #B7B7B7;border-collapse: collapse;background-color:#E7E7E7;height:auto;">
 <tr>
   <td style="color:#CC0000;">
     Een of meerdere verplichte velden ontbreken.
   </td>
 </tr>
</table>

即使是米尔德尔·韦尔普利希特·维尔登·翁布里肯。
我试过这个:

$("#errorMessage").append("<table id="error" style="width:900px;border-top: 1px Solid #B7B7B7;border-right: 1px Solid #B7B7B7; border-left: 1px Solid #B7B7B7;border-collapse: collapse;background-color:#E7E7E7;height:auto;"></table>");

    $("#error").append("<tr><td style="color:#CC0000;">Message</td></tr>
$(“#errorMessage”)。追加(“”);
$(“#错误”).append(“消息
我找不到正确的方法。有人能帮忙吗? 感激:)

您正在使用“两次”。尝试将“用于外部html标记”和“仅用于id和样式等属性”

$("#errorMessage").append('<table id="error" style="width:900px;border-top: 1px Solid #B7B7B7;border-right: 1px Solid #B7B7B7;
border-left: 1px Solid #B7B7B7;border-collapse: collapse;background-color:#E7E7E7;height:auto;"></table>');
$(“#errorMessage”).append(“”);
$(“#errorMessage”).append(``);
$(“#错误”).append(`Message`);
看一下结束和开始的引号,当您填充html属性时,引号会立即退出字符串,因为您使用了双引号( " )

你可以使用一个单引号作为你的开场白,或者像我在代码中所做的那样,在一个反勾上


#错误{
宽度:900px;
边框顶部:1px实心#b7b7;
右边框:1px实心#b7b7;
左边框:1px实心#b7b7;
边界塌陷:塌陷;
背景色:#E7E7E7;
高度:自动;
}
.tdinsideError
{
颜色:#CC0000;
}
var errorContent=''+customMessage+'';//如果是自定义消息。
var errorContent='Een of Meerderere verplichte velden ontbreken.';//如果没有自定义消息。
$(document.find(“#errorMessage”).html(errorContent)//方法1
$(document.find(“#errorMessage”).html($(“”).addClass(“error”).attr(“id”,“error”))//方法1
$(“”).addClass(“fa plus”)

我建议使用
document.createElement()
(搜索MDN以了解更多信息)创建元素,而不是将所有元素HTML作为字符串编写,因为作为字符串,在参数列表之后读取
“Uncaught SyntaxError:missing”)似乎非常糟糕,
!!!哪个部门!?!如果您打算在标记中使用双引号-我建议您在包装字符串中使用单引号,例如
$(“#error”).append('Message')谢谢你帮助我,这是非常有用的。我把所有的东西都修好并开始工作了!:)
$("#errorMessage").append(`<table id="error" style="width:900px;border-top: 1px Solid #B7B7B7;border-right: 1px Solid #B7B7B7; border-left: 1px Solid #B7B7B7;border-collapse: collapse;background-color:#E7E7E7;height:auto;"></table>`);
$("#error").append(`<tr><td style="color:#CC0000;">Message</td></tr>`);
<style type="text/css">
    #error{
        width:900px;
        border-top: 1px Solid #B7B7B7;
        border-right: 1px Solid #B7B7B7;
        border-left: 1px Solid #B7B7B7;
        border-collapse: collapse;
        background-color:#E7E7E7;
        height:auto;
    }
    .tdinsideError
    {
        color:#CC0000;
    }
</style>
<div id="errorMessage"></div>
<script type="text/javascript">
    var errorContent = '<table id="error"><tr><td class="tdinsideError">'+customMessage+'</td></tr></table>'; // if  custom message.
    var errorContent = '<table id="error"><tr><td class="tdinsideError">Een of meerdere verplichte velden ontbreken.</td></tr></table>'; // if no custom message.
    $(document).find("#errorMessage").html(errorContent);//method 1
    $(document).find("#errorMessage").html($("<table>").addClass("error").attr("id",'error'));//method 1
    $("<span>").addClass("fa fa-plus")
</script>
<!--
    <table id="error">
        <tr>
            <td class="tdinsideError">Een of meerdere verplichte velden ontbreken.</td>
        </tr>
    </table>
-->