Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在单独的页面上链接到div,并在单击链接时突出显示div_Javascript_Jquery - Fatal编程技术网

Javascript 在单独的页面上链接到div,并在单击链接时突出显示div

Javascript 在单独的页面上链接到div,并在单击链接时突出显示div,javascript,jquery,Javascript,Jquery,我试图突出显示侧导航上链接的特定div onclick。到目前为止,它可以工作(在默认页面上),但当您转到其他页面,然后单击侧导航中的某个项目时,它将定位到指定的div,但不会高亮显示。我需要重新点击链接,以便突出显示 var App = { SetBaseLine: function() { jQuery("#priceRange, #satisfaction").removeClass("activeListColor"); } }; jQuery(document

我试图突出显示侧导航上链接的特定div onclick。到目前为止,它可以工作(在默认页面上),但当您转到其他页面,然后单击侧导航中的某个项目时,它将定位到指定的div,但不会高亮显示。我需要重新点击链接,以便突出显示

var App = {
    SetBaseLine: function() {
    jQuery("#priceRange, #satisfaction").removeClass("activeListColor");
    }
};

jQuery(document).ready(function() {
    jQuery('a#priceLink').click(function(e) {
        App.SetBaseLine();
        jQuery('#priceRange').addClass('activeListColor');
    });
    jQuery('a#satisfactionLink').click(function(e) {
        App.SetBaseLine();
        jQuery('#satisfaction').addClass('activeListColor');
    });


    <div id="priceRange">
            <div class="header">Price Range<br /><a id="button1" href="javascript:toggle3('colcontent1','button1');" ><img src="images/more-info-button.png" width="76" height="20" /></a></div>
            <div class="col2 topSpace">Packages  start at $29.99/month</div>
            <div class="col3"><span>Best Value</span><img src="images/red-trophy.png" class="trophy" /><br />Packages  start at $19.99/month</div>
            <div class="col4 topSpace">Packages  start at $29.99/month</div>
    </div> <!-- End of priceRange div -->

<div id="satisfaction">
         <div class="header">Customer Satisfaction <br /><a id="button2" href="javascript:toggle3('colcontent2','button2');" ><img src="images/more-info-button.png" width="76" height="20" /></a></div>
            <div class="col2 topSpace">American  Customer Satisfaction Index (ACSI) Rating: 68 </div>
            <div class="col3"><span>Most Popular</span><img src="images/red-trophy.png" class="trophy" /><br />American  Customer Satisfaction Index (ACSI) Rating: 71 </div>
            <div class="col4 topSpace">American  Customer Satisfaction Index (ACSI) Rating: 61 </div>
    </div> <!-- End of satisfaction div -->
var-App={
SetBaseLine:函数(){
jQuery(“价格范围,满意度”).removeClass(“activeListColor”);
}
};
jQuery(文档).ready(函数(){
jQuery('a#priceLink')。单击(函数(e){
App.SetBaseLine();
jQuery('#priceRange').addClass('activeListColor');
});
jQuery('a#satisfactionLink')。单击(函数(e){
App.SetBaseLine();
jQuery(“#满意度”).addClass('activeListColor');
});
价格范围
套餐起价为每月29.99美元 最佳价值
套餐起价为19.99美元/月 套餐起价为每月29.99美元 客户满意度
美国客户满意度指数(ACSI)评级:68 最受欢迎的
美国客户满意度指数(ACSI)评级:71 美国客户满意度指数(ACSI)评级:61

任何建议???

当您更改页面时,DOM没有及时准备好删除和添加突出显示类


因此,您可以设置一个全局变量,当您加载包含要突出显示的列表项的页面时,检查该变量的值并突出显示相应的列表项,然后将其置零。

您的jQuery ready函数没有关闭(
。这只是复制/粘贴遗漏,还是这是您的实际代码?我认为您需要将页面参数传递到新页面。Stackoverflow具有突出显示注释或答案的策略。去做超现实的梦——道歉。这是一个复制粘贴错误。对Tooraj来说-我不确定你说的是哪一部分?您可以澄清一下吗?您需要检查url,如果加载页面上存在锚,而不仅仅是单击事件