JS location.href accept parameters and parameter passing

The current page parameter passing

window.location.href="realNameAuthenticationResult.html?type="+1 + "&name="+"zhangchenxao";

Next page accept parameters

 var url = location.search // Get the character string after the url "?" ( 'Business & Role = modFlag. 1 =?') 
 var theRequest = new new Object ()
  IF (url.indexOf ( ' ? ' ) = -! . 1 ) {
  var STR url.substr = ( . 1 ) // substr () method returns the string parameter values from the start to the end; 
 var STRs = str.split ( ' & ' )
  for ( var I = 0 ; I <STRs. length; I ++ ) { 
    theRequest [STRs [I] .split ( ' = ' ) [ 0 ]] = STRs [I] .split (' = ' ) [ . 1 ] 
 } the console.log (theRequest)
 // at this time is the parameter we need theRequest; 
the console.log (theRequest.type) 
 }

 

 

Guess you like

Origin www.cnblogs.com/xiaoxiao2017/p/11819813.html