ASP.NET 链接按钮生成错误标记

发布于 2024-08-13 15:30:13 字数 2239 浏览 4 评论 0 原文

我在链接按钮生成不正确的标记时遇到一些问题。

它应该生成如下内容:

<div style="margin-top: 5px; width: 150px; margin-left: auto; margin-right: auto;">
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
        <div>
            <span class="border top">
                <span class="border">
                </span>
            </span>
            <span class="icon cancel">
                Cancel
            </span>
            <span class="border bottom">
                <span class="border">
                </span>
            </span>
        </div>
    </a>
</div>

仅注意一个标签。

有时它最终会生成以下内容:

<div style="margin-top: 5px; width: 150px; margin-left: auto; margin-right: auto;">
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
    </a>
    <div>
        <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
        class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
            <span class="border top">
                <span class="border">
                </span>
            </span>
            <span class="icon cancel">
                Cancel
            </span>
            <span class="border bottom">
                <span class="border">
                </span>
            </span>
        </a>
    </div>
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
    </a>
</div>

现在注意 3(!) 个锚标记。

它只发生在特定服务器上的特定浏览器上,服务器在 IIS 6 上运行 ASP.NET 2.0,使用 Firefox 3.5 访问页面。

更新:我使用 FF 查看源代码查看代码,没有安装插件,该文档据称是 XHTML 1.1 Transitional,但我认为它无效,因为锚标记内不能有 div 标记。

I'm having some trouble with a Link Button generating incorrect mark up.

It should generate something like this:

<div style="margin-top: 5px; width: 150px; margin-left: auto; margin-right: auto;">
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
        <div>
            <span class="border top">
                <span class="border">
                </span>
            </span>
            <span class="icon cancel">
                Cancel
            </span>
            <span class="border bottom">
                <span class="border">
                </span>
            </span>
        </div>
    </a>
</div>

Notice only one tag.

It ends up generating sometimes this:

<div style="margin-top: 5px; width: 150px; margin-left: auto; margin-right: auto;">
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
    </a>
    <div>
        <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
        class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
            <span class="border top">
                <span class="border">
                </span>
            </span>
            <span class="icon cancel">
                Cancel
            </span>
            <span class="border bottom">
                <span class="border">
                </span>
            </span>
        </a>
    </div>
    <a onclick="return JSConfirm('Confirm?');" id="ctl00_cntPrincipal_btnCancel"
    class="round-corner opt-upload cancel" href="javascript:__doPostBack('ctl00$cntPrincipal$btnCancel','')">
    </a>
</div>

Notice now 3 (!) anchor tags.

It only happens on a specific server to a specific browser, server is running ASP.NET 2.0 on IIS 6 using Firefox 3.5 to access the page.

Update: I view the code using FF view source, no plugins installed, the document is supposedly XHTML 1.1 Transitional, but I don't think it validates since you can't have div tag inside anchor tags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2024-08-20 15:30:13

您如何看待该标记?在萤火虫中?在安装了 TidyHTML 的 FF 源代码查看器中?

使用什么 (X)HTML 声明? HTML 4.1? XHTML 过渡?严格的?

我问的原因是 标记被定义为 内联 元素,因此将其包裹在 周围是不合法的em> 元素,例如

标记。

您在 FF 中看到的源代码可能已通过在 div 标记内部和末尾添加额外的锚标记来解决此问题。

您如何看待该标记?在萤火虫中?在安装了 TidyHTML 的 FF 源代码查看器中?

使用什么 (X)HTML 声明? HTML 4.1? XHTML 过渡?严格的?

我问的原因是 标记被定义为 内联 元素,因此将其包裹在 周围是不合法的em> 元素,例如

标记。

您在 FF 中看到的源代码可能已通过在 div 标记内部和末尾添加额外的锚标记来解决此问题。


不,查看源代码是 FF 修复的 - 如果您想检查这一点,您可以安装 ViewSourceWith 插件,并在您选择的记事本中查看源代码 - 我注意到这两者之间的差异。

与 ASP.NET 1.1 不同,ASP.NET 2.0 中的 BrowserCaps 确实可以识别 FF、Safari 等,因此一般输出应该与您在 IE 中看到的内容没有太大不同。

How are you seeing that markup? In Firebug? In the FF source viewer with TidyHTML installed?

What (X)HTML declaration are using using? HTML 4.1? XHTML Transitional? Strict?

The reason I ask, is that the <a> tag is defined as an inline element, so it is not legal to wrap it around a block element, such as a <div> tag.

The source you are seeing in FF has probably been corrected to handle this, by adding the additional anchor tags inside and at the end of the div tag.

How are you seeing that markup? In Firebug? In the FF source viewer with TidyHTML installed?

What (X)HTML declaration are using using? HTML 4.1? XHTML Transitional? Strict?

The reason I ask, is that the <a> tag is defined as an inline element, so it is not legal to wrap it around a block element, such as a <div> tag.

The source you are seeing in FF has probably been corrected to handle this, by adding the additional anchor tags inside and at the end of the div tag.


Nope, the View Source is as FF fixes it up - if you want to check this, you can install the ViewSourceWith plugin, and view the source in your NotePad of choice - I've noticed differences between these two.

Unlike ASP.NET 1.1, the BrowserCaps in ASP.NET 2.0 do recognise FF, Safari, etc, so the general output shouldn't be that different to what you see in IE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文