【发布时间】:2014-01-22 10:38:20
【问题描述】:
我正在尝试改进我的网站,添加将在每个页面中都有的部分,并在我更新文件时自动更新:我知道有很多方法,但我仍然是初学者,我决定使用 jQuery。问题是我使用了<table>,因为我有一个栏 div,它需要位于 HTML 中的内容旁边。我在表头、表格的开始标签(包括 tr 和 td)及其内容之前加上了标签的结束。 HTML 包含栏附近的任何内容:确实如此!但它在栏下:我不太确定发生了什么:我的想法是 XHTML 在附加之前自动关闭标签,因为在 HTML 中它没有找到它们......我将包括我们的代码有兴趣
$(document).ready(function(){
$('body').prepend('<table><tr><td>Text</td><td>');
$('body').append('</td></tr></table>');
})
那是 jQuery 代码,我可以确保你有正确的链接到脚本和 jQuery (+UI) 的工作。现在一切都应该很简单:您只需在 .html 文件中添加您的 HTML 代码...但是不!
<html>
<head>
<title>Cheese</title>
<script to my script and jQuery library/>
</head>
<body>
<!-- here should go what I prepended, and it does,
but closes the <table></td></tr> tags aswell -->
This should be to the side of 'Text' and comprehended in the table, in a td
<!-- here should go what I appended,
but strangely it doesn't -->
</body>
</html>
我做错了吗?如果您在这里没有发现任何问题,我会将所有代码发送给您,提前谢谢!
【问题讨论】:
标签: jquery html xhtml append prepend