javascript - 奇怪的 html 渲染异常。

标签 javascript html css django web

我不确定这个问题是在 Django 中还是在 HTML 中,所以我将两者都包括在内。这是我在右键单击并选择“查看源代码”时看到的 html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="/static//CSS/postingformstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div style="width:100%;">

    <span class="posting_title">Original Work</span>

    <form action="" method="post" class="base_form">
        <p><label for="id_title">Title:</label> <input type="text" name="title" id="id_title" /></p>
        <input type="hidden" name="id">8</input>
        <input type="submit" class="posting_button">Post</input>
    </form>
</div>
</body>
</html>

这是我在 google chrome 中单击检查元素时得到的,以及似乎呈现的内容。您注意到表单中所有的结束标记都丢失了。

<html xmlns="http://www.w3.org/1999/xhtml"><head>


    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <link type="text/css" rel="stylesheet" href="/static//CSS/postingformstyle.css">
</head><body>
<div style="width: 100%;">

    <span class="posting_title">Original Work</span>

    <form class="base_form" method="post" action="">
        <p><label for="id_title">Title:</label> <input type="text" id="id_title" name="title"></p>
        <input type="hidden" name="id">8
        <input type="submit" class="posting_button">Post
    </form>
</div>
</body></html>

这是CSS:

.posting_button {
    display:block;
    font-size:20px;
    width:100%;
}
.posting_title {
    text-align:center;
    display:block;
    color:black;
    font-size:30px;
    font-family:Arial, Helvetica, sans-serif;
    margin: 2px 0 15px 0;
}
.base_form label {
    font-size: 17px;
    font-family: arial;
    font-weight: bold;
    display: block;
}
.base_form > p {
    margin: 2px 0 5px 0;
}

这是 Django(如果有问题的话):

模板:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="{{ STATIC_URL }}/CSS/postingformstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div style="width:100%;">

    <span class="posting_title">Original Work</span>

    <form action="" method="post" class="base_form">
        {{ form.as_p }}
        <input type="hidden" name="id">{{ id }}</input>
        <input type="submit" class="posting_button">Post</input>
    </form>
</div>
</body>
</html>

View .py

def posting_story_ow(request):
    if request.method == 'POST':
        d = 12
    return render_to_response('Posting/Forms/posting_post_ow.html', {'STATIC_URL':STATIC_URL, 'id' : request.GET['id'], 'alertnum': 0, 'form': post_ow})

最佳答案

问题出在您的 HTML 上。输入标签不应该有打开和关闭。

为了实现您想要实现的目标:

<input type="hidden" name="id">{{ id }}</input>

你应该这样做:

<input type="hidden" name="id" value="{{ id }}">

编辑:如果您感兴趣,请说明:http://www.w3.org/TR/html401/interact/forms.html#h-17.4

关于javascript - 奇怪的 html 渲染异常。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208194/

相关文章:

html - "aria-labelledby"属性的功能

javascript - 在 lakh/crore 系统中将数字转换为单词

javascript - 如何修复用 Javascript 制作的实时时钟(我在网页中看不到它)?

javascript - 第一个编程游戏的问题(javascript/jQuery)

html - 为什么 div 区域仍然比图像 css 更大?

jQuery:第 n 个子选择器在 ie7 中不起作用

javascript - ASP.NET MVC4 显示模式不加载 TypeScript 输出

javascript - 什么 Web 浏览器引擎、版本和功能用于在 Visual Studio 2010 中显示网页?

javascript - ExtJs 中的多列组合

html - 我的专栏将在 Firefox/Safari 中换行,但它在 Chrome 中有效