删除包含外部html页面的javascript变量中的html标记

Remove html tag inside a javascript variable that contains an external html page

本文关键字:html javascript 变量 标记 包含外 删除      更新时间:2023-09-26

我一直试图从项目中jquery对话框中显示的外部html表单中删除一个div。

这两个网页都属于我的公司,我们的想法是通过对话框在主网站内显示我们的问题跟踪工具(位于不同的公司域中)的形式,这样只需填写即可立即添加问题,而无需从外部访问该工具。

到目前为止,这是有效的(在对话框中显示外部形式):

function ShowPopup(message) {
        $(function () {
            var pweb = '<object data="http://[internal domain]" width="1024px" height="768px" />';
            $("#dialog").html(pweb);
            $("#dialog").dialog({
                title: "jQuery Dialog Popup",
                minHeight: 768,
                minWidth:1024,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
        });
    };

现在,在显示表单之前,我需要删除表单中名为"report_issue_header"的div

$("#dialog").html(pweb);
var teaser = $("#dialog").clone();
teaser.find(".report_issue_header").remove()

$("#dialog").html(pweb);
var teaser = $("#dialog").clone();
teaser = $.trim($(".report_issue_header", teaser).remove().end().html());

正如我在这里发现的:jquery删除变量(jquery对象)中的html元素

但它似乎不起作用。

我也试过这个javascript:

pweb.getElementsByTagName("report_issue_header").remove();

还有很多类似的方法,但没有什么能奏效。我承认我是一名C程序员,对Javascript几乎没有经验,不过我猜这与我如何管理变量中的外部代码有关。在我看到的其他例子中,他们只使用$(this)。并使用jQuery,它可以正常工作。。。

我注意到的第一件事是您克隆了元素,所以您要删除的实际上是克隆的元素,为什么不尝试

$("#dialog").html(pweb).find(".report_issue_header").remove();