2010-11-12 15 views
21

मुझे समझ में नहीं आता कि एक चर घोषित करने के लिए सबस्ट्रिंग विधि का उपयोग करके मुझे त्रुटि संदेश क्यों मिलता है।.substring त्रुटि: "कोई फ़ंक्शन नहीं है"

मैं तुलना में यूआरएल के पहले भाग का उपयोग करना चाहता हूं।

साइट:

var currentLocation = document.location, 
muzLoc = currentLocation.substring(0,45), 
prodLoc = currentLocation.substring(0,48), 
techLoc = currentLocation.substring(0,47); 

त्रुटि:

"currentLocation.substring कार्य नहीं है" लेकिन कोड के इस भाग है http://www.elizabet.nl/wordpress

यह बात यह है कि गलत हो रहा है है ठीक है:

var URL = $(this).attr("href").substring(2) + ' #main'; 

सभी कोड:

jQuery(function($){ 

    var siteURL = "http://" + top.location.host.toString() + "/wordpress", // Declareren van URL van de website. 
     URL = '', // Declareren van een URL, welke dan ook. 
     currentLocation = '', 
     muzLoc = '', 
     prodLoc = '', 
     techLoc = '',    
     allLinks = $('a[href^=' + siteURL + ']'), // Declareren van alle menu-links. Het teken^betekent 'begint met'. 
     otherLinks = $('a[href^=' + siteURL + "/wp-content" + ']'), 
     siteLinks = $(allLinks).not(otherLinks),  
     mainDiv = $("#content"), 
     hash = window.location.hash, 
     muziekURL = "http://www.elizabet.nl/wordpress/#/muziek_pf/", 
     productieURL = "http://www.elizabet.nl/wordpress/#/productie_pf/", 
     techniekURL = "http://www.elizabet.nl/wordpress/#/techniek_pf/";  

    if (hash) { 
     hash = "/wordpress" + hash.substring(1); // substring methode haalt karakters van je string af. In dit geval de #, vanwege de offset=1. 
     URL = hash; 
     $(mainDiv).load(URL);   
    } 

function pageLoad() { 

       var allLinks = $('a[href^=' + siteURL + ']'), 
       otherLinks = $('a[href^=' + siteURL + "/wp-content" + ']'), 
       siteLinks = $(allLinks).not(otherLinks); 

       siteLinks.each(function() {    

        $(this).attr("href", "#" + this.pathname.substring(10)); 
        }) 

        .click(function() { 
        var URL = $(this).attr("href").substring(2) + ' #main'; 
        $(mainDiv).load(URL, function(){ 

        var currentLocation = document.location, 
         muzLoc = currentLocation.substring(0,45), 
         prodLoc = currentLocation.substring(0,48), 
         techLoc = currentLocation.substring(0,47);     

       if (muzLoc == muziekURL) {    
       $("body").animate({ backgroundColor: "#151C07"}, 500); 
       $(".nieuws").animate({ borderBottomColor: "#99CC33"}, 500); 
       $("#stripe_trans").add("#header").animate({ backgroundColor: "#99CC33"}, 500); 
       $("#tabtekst_3").stop().animate({ backgroundColor: "#B8860B" }, 500); 
       $("#tab_3").add("a.gold").stop().animate({ color: "#B8860B" }, 500); 
       $("#tabtekst_4").stop().animate({ backgroundColor: "#765AAD" }, 500); 
       $("#tab_4").add("a.purple").stop().animate({ color: "#765AAD" }, 500);          
       } 

       else if (prodLoc == productieURL) {  
       $("body").animate({ backgroundColor: "#251B02"}, 500); 
       $(".nieuws").animate({ borderBottomColor: "#FFCC33"}, 500); 
       $("#stripe_trans").add("#header").animate({ backgroundColor: "#FFCC33"}, 500);     
       $("#tabtekst_2").stop().animate({ backgroundColor: "#6B8E23" }, 500); 
       $("#tab_2").add("a.green").stop().animate({ color: "#6B8E23" }, 500); 
       $("#tabtekst_4").stop().animate({ backgroundColor: "#765AAD" }, 500); 
       $("#tab_4").add("a.purple").stop().animate({ color: "#765AAD" }, 500); 
       } 

       else if (techLoc == techniekURL) {  
       $("body").animate({ backgroundColor: "#181223"}, 500); 
       $(".nieuws").animate({ borderBottomColor: "#B39BE4"}, 500); 
       $("#stripe_trans").add("#header").animate({ backgroundColor: "#B39BE4"}, 500);   
       $("#tabtekst_2").stop().animate({ backgroundColor: "#6B8E23" }, 500); 
       $("#tab_2").add("a.green").stop().animate({ color: "#6B8E23" }, 500);      
       $("#tabtekst_3").stop().animate({ backgroundColor: "#B8860B" }, 500); 
       $("#tab_3").add("a.gold").stop().animate({ color: "#B8860B" }, 500); 
       } 

       else { 
       $("body").animate({ backgroundColor: "#202020"}, 500); 
       $(".nieuws").animate({ borderBottomColor: "#FFF"}, 500); 
       $("#stripe_trans").add("#header").animate({ backgroundColor: "#FFF"}, 500);    
       $("#tabtekst_2").stop().animate({ backgroundColor: "#6B8E23" }, 500); 
       $("#tab_2").add("a.green").stop().animate({ color: "#6B8E23" }, 500);    
       $("#tabtekst_3").stop().animate({ backgroundColor: "#B8860B" }, 500); 
       $("#tab_3").add("a.gold").stop().animate({ color: "#B8860B" }, 500); 
       $("#tabtekst_4").stop().animate({ backgroundColor: "#765AAD" }, 500); 
       $("#tab_4").add("a.purple").stop().animate({ color: "#765AAD" }, 500);           
       } 

       pageLoad(); 
      });    
     }); 
} 

pageLoad(); 


}); // End document ready function. 

उत्तर

30

document.location एक वस्तु, न कोई स्ट्रिंग है। यह पूर्ण पथ (डिफ़ॉल्ट रूप से) देता है, लेकिन वास्तव में इससे अधिक जानकारी होती है। समाधान के लिए

शॉर्टकट: document.location.toString().substring(2,3);

या का उपयोग document.location.href या window.location.href

1

आप कर सकते हैं भी बोली स्ट्रिंग

''+document.location+''.substring(2,3); 
1

लेखन त्रुटि: hex.substring नहीं एक समारोह

हल है:

आपको

hex = '0x4a6f7264616e0000000000000000000000000000000000000000000000000000' 
//because you probably only coppied the hexcode, you need to copy the quotes too 
करने की आवश्यकता है
संबंधित मुद्दे