簡體   English   中英

on.click刪除部分網址中的任何網址 <div> 然后加載

[英]on.click remove part of any url in a <div> and then load it

當用戶單擊時,我想從我的任何URL中刪除/ groups /

背景是我有一個wordpress小部件,該小部件顯示到頁面(BP組)的鏈接,並且我希望用戶單擊時將用戶發送到我為每個組創建的頁面(因為我無法在buddypress中創建主頁)。

我已將頁面網址設置為與群組頁面相同,但沒有/ groups /,因此,如果將其刪除,則該小部件會將用戶重定向到我的頁面。

例如,訪客被發送到: http : //focallocal.org/up-cycling-workshop-with-londons-homeless/而不是http://focallocal.org/groups/up-cycling-workshop-with-londons-無家可歸/

我多年來一直在研究它,這是我能想到的最好的方法(我不會講js):

'onclick="location.replace(/groups/,"")'

編輯請求的html:

關閉活動,團體和項目最新| 活躍 流行

        <ul id="groups-list" class="item-list">
                                <li class="odd public is-admin is-member">
                    <div class="item-avatar">
                        <a href="h t t p://focallocal. org/groups/up-cycling-workshop-with-londons-homeless/" title="Up-cycling Workshop with the Homeless"><img src="h t t p://focallocal. org/wp-content/uploads/group-avatars/4/a4ce0d8153497b96869a9b46e7ff391f-bpthumb.jpg" class="avatar group-4-avatar avatar- photo" width="50" height="50" alt="Group logo of Up-cycling Workshop with the Homeless" title="Up-cycling Workshop with the Homeless"></a>
                    </div>

                    <div class="item">
                        <div class="item-title"><a href="h t t p://focallocal. org/groups/up-cycling-workshop-with-londons-homeless/" title="Up-cycling Workshop with the Homeless">Up-cycling Workshop with the Homeless</a></div>
                        <div class="item-meta">
                            <span class="activity">
                            active 1 week, 1 day ago                                </span>
                        </div>
                    </div>
                </li>

                                <li class="even public is-admin is-member">
                    <div class="item-avatar">
                        <a href=" h t t p://focallocal. org/groups/public-relations-marketing-and-advertising-team/" title="Public Relations, Marketing and Advertising Team"><img src="http://focallocal.org/wp-content/uploads/group-avatars/2/05196f60439a3fe01b9855f267805180-bpthumb.jpg" class="avatar group-2-avatar avatar- photo" width="50" height="50" alt="Group logo of Public Relations, Marketing and Advertising Team" title="Public Relations, Marketing and Advertising Team"></a>
                    </div>

                    <div class="item">
                        <div class="item-title"><a href="h t t p://focallocal. org/groups/public-relations-marketing-and-advertising-team/" title="Public Relations, Marketing and Advertising Team">Public Relations, Marketing and Advertising Team</a></div>
                        <div class="item-meta">
                            <span class="activity">
                            active 1 month, 3 weeks ago                             </span>
                        </div>
                    </div>
                </li>

                                <li class="odd 
                        </ul>
        <input type="hidden" id="_wpnonce-groups" name="_wpnonce-groups" value="e2870f6aee"><input type="hidden" name="_wp_http_referer" value="/">         <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="300">


    </div>  </div></div><div id="tab_slide_background" class="tab_slide_corners_right"></div></div></div>

我看到您正在使用jQuery,因此您可以執行以下操作:

$('#groups-list a').each(function(){
   var $this = $(this); 
   var href = $this.attr('href');

    href = href.replace('groups/', '');
    $this.attr('href', href);

});

您也可以這樣做:

 $('#groups-list a[href*="groups"]').each(function(){ this.href = this.href.replace('/groups', '');  });

純JavaScript

 var anchors = document.querySelectorAll( "#groups-list a[href*='group']");

for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
anchor.href = anchor.href.replace('/groups', '');

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM