在SharePoint列表页面中,我试图覆盖“编辑项”图标上发生的情况,然后转到我自己的URL。
完整元素如下:
<a unselectable="on" href="javascript:;" onclick="return false;" class="ms-cui-ctl-large " aria-describedby="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/inc/1033/ipfsimages.png" style="top: -32px; left: -32px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Edit<br>Item</span></a>
我已经在同一页面上匹配了其他元素,没有任何问题。这个特殊的人很难。
我尝试了这两种方法,但没有得到:
$('a[id="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit-Large"]').removeAttr("onclick").click(function() {
location.href = "https://mycustomurl";
});
$('a[id="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit-Large"]').attr('href','https://mycustomurl');
谢谢您的帮助!
答案 0 :(得分:0)
您需要删除onclick
属性,我注意到它返回的是false,所以不要冒泡或遵循href。
.attr("onclick", "")
$('a[id="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit-Large"]').attr('href', 'www.google.ca').attr("onclick", "");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a unselectable="on" href="javascript:;" onclick="return false;" class="ms-cui-ctl-large " aria-describedby="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.ContextualTabs.InfoPathListDisplayTab.Manage.Controls.btnEdit-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/inc/1033/ipfsimages.png" style="top: -32px; left: -32px;"></span></span>
<span unselectable="on" class="ms-cui-ctl-largelabel">Edit<br>Item</span>
</a>