如何在jquery中查找和替换outerHTML

时间:2017-03-03 13:10:03

标签: jquery asp.net-mvc

我想找到并替换outerHtml内容。

有一个" NSE_View_Delete" class,我想用" NSE_View_Delete_only_for_demo"替换它。

我该怎么办..请帮忙..

这是我的隐藏地点..

 @Html.Hidden("ViewGroupDetails", Url.Action("ViewGroupDetails", "NSEDownload", new { acid = InsiderTrading.Common.ConstEnum.UserActions.NSEDownload }), new { @class = "gridtypecontrol", ctrtype = "link", gridcolumntype = @ViewBag.GridType + "_usr_grd_11073", param = "{'id':'MyID','class':'NSE_View_Delete','text':'','href':'" + Url.Action("ViewGroupDetails", "NSEDownload", new { acid = InsiderTrading.Common.ConstEnum.UserActions.NSEDownload }) + "& GroupId=<GroupId>','text':'View/Delete'}" })

它在dom中呈现为outerHTML(在浏览器中),如下所示

<input class="gridtypecontrol" ctrtype="link" gridcolumntype="508005_usr_grd_11073" id="ViewGroupDetails" name="ViewGroupDetails" param="{'id':'MyID','class':'NSE_View_Delete','text':'','href':'/NSEDownload/ViewGroupDetails?acid=223&amp; GroupId=<GroupId>','text':'View/Delete'}" type="hidden" value="/NSEDownload/ViewGroupDetails?acid=223">

js代码如下:

 if (obj.aData['nse_grd_50431'] != null) {
                debugger;
                var abc = obj.aData['nse_grd_50431'];

                if(abc==0)
                {

                    debugger;

                    var dom_value = $("#ViewGroupDetails").get(0);

                    var abc= dom_value.outerHTML.replace('param="class: NSE_View_Delete_only_for_demo;"')

                    alert(abc);
                }
            }

请帮助..

2 个答案:

答案 0 :(得分:0)

我想您正在尝试替换HTML元素的属性,如果是这种情况,您可以使用 attr()方法,如下所示

$("#ViewGroupDetails").attr("param").replace("NSE_View_Delete", "NSE_View_Delete_only_for_demo")

答案 1 :(得分:0)

这不是outerHTML这是属性,所以你应该替换它。 https://www.w3schools.com/jquery/jquery_dom_set.asp