location.reload 多次加载..点击时只需重新加载一次

location.reload loads multiple times.. Have to reload only once on click

根据客户要求,我需要重新加载特定的 div 容器区域。是否可以在没有 ajax 的情况下在点击时刷新 div 容器?

相反,我尝试使用以下代码刷新页面,

 $('li.status-item a').click(function() {
    window.location.href=window.location.href;
});

$('li.status-item a').click(function() {
    location.reload();
});

这两种代码在我的本地环境中都运行良好。当我在我们的 CMS 环境中实现它时,在单击 link 后每秒自动刷新页面。不确定为什么它会自动加载。需要一些专业知识来解决问题。

请检查此 link 的屏幕截图,

http://teshdigitalgroup.com/team/reload.JPG

HTML代码:

<ul>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('retire')">
        <img srcset="images/icons/retire.png" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>

谢谢

试试这个..

   <ul>
<li class="status-item">
    <a href="javascript:;" id="single" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:;" id="attached" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:;" id="family" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:" id="retire"  data-ng-click="setProfileStatus('retire')">
        <img srcset="images/icons/retire.png" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>
   <script>
$("li.status-item a").click(function() {
var url=document.URL;
var res = url.split("?");
var id=$(this).attr("id");
    if (window.location.href.indexOf(id)==-1) {
         window.location.href=res[0]+'?'+id;

    }

});
</script>

能否在我的 JSfiddle 中复制您的问题。我试过你的代码每次点击它只重新加载一次。您的代码已在下面更新 link

http://jsfiddle.net/ilaiya/72c5bvdy/1/

代码:

$('li.status-item a').click(function() {
    alert('Reload');
    location.reload();
});

<ul>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('retire')">
        <img srcset="" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>