简体   繁体   English

如何显示HTML生成的文本而不是标签

[英]How to display HTML generated text instead of the tags

I am using JQuery Dialog to display some text which has HTML tag included: 我正在使用“ jQuery对话框”显示一些包含HTML标记的文本:

<div id="dialog" style="display: none">
    <p id='infoShow'></p>
</div>

The JQuery which displays the data is: 显示数据的JQuery是:

function test(element) {

        $("#infoShow").html($(".gLine", $(element).closest("tr")).html());
        $("#dialog").dialog({
            title: "View Guideline",
            buttons: {
                Ok: function () {
                    $(this).dialog('close');
                }
            },
            modal: true,
            width: "450px"
        });

    }

It is invoked by an ASP LinkButton: 它由ASP LinkBut​​ton调用:

<asp:LinkButton runat="server" ID="btnShow3" CssClass="btnSearch3" Text="VIEW" OnClientClick="javascript:test(this);return false;"></asp:LinkButton>

Although I am using the .html() to display the output, it is still showing the HTML tags instead of the output: 尽管我使用.html()来显示输出,但它仍显示HTML标记而不是输出:

在此处输入图片说明

How can I modify the code so it generates the HTML tag instead of just displaying as plain text? 如何修改代码,使其生成HTML标记,而不仅仅是显示为纯文本?

尝试这个:

$("#infoShow").append( $( HTML_TEXT_STRING));

in your span id "whatever the id is" 在您的范围ID“无论ID是什么”中

you can use .text(): 您可以使用.text():

$('#your-span-id').text($('#your-span-id').text());

this will strip all the html tags and then you can display it on your modal. 这将删除所有html标记,然后您可以将其显示在模式中。 you have to use your span id twice because the nature of the mechanism. 由于该机制的性质,您必须两次使用您的span id。 this should work. 这应该工作。

Remove the "dialog" div and "infoShow" tags since you don't need them. 删除“ dialog” div和“ infoShow”标签,因为您不需要它们。

Then, instead of writing to an existing div, just append a fresh div to the body element as a dialog, like so: 然后,无需写入现有的div,只需将一个新的div作为对话框添加到body元素,如下所示:

function test(element) {

    $("<div></div>").appendTo('body')
    .html($(".gLine", $(element).closest("tr")).html())
    .dialog({
        title: "View Guideline",
        buttons: {
            Ok: function () {
                $(this).dialog('close');
            }
        },
        modal: true,
        width: "450px"
    });

}

Or, you could do it like this: 或者,您可以这样做:

function test(element) {

    $("<div>" + $(".gLine", $(element).closest("tr")).html() + "</div>").appendTo('body')
    .dialog({
        title: "View Guideline",
        buttons: {
            Ok: function () {
                $(this).dialog('close');
            }
        },
        modal: true,
        width: "450px"
    });

}
$(".gLine", $(element).closest("tr"))

This syntax is wrong. 此语法是错误的。 You can't separate a class name and a jquery element with a comma, and wrap it with '$'. 您不能用逗号分隔类名和jquery元素,并用'$'将其包装起来。 The comma is for css selectors like .gLine, .herpDerp 逗号用于.gLine, .herpDerp等CSS选择器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM