原型——parseQuery() 方法



此方法會解析類 URI 查詢字串並返回由引數/值對構成的物件。此方法類似於 toQueryParams();

此方法真正用於解析查詢字串(因此,分隔符引數的預設值為“&”)。

語法

string.parseQuery([separator = '&']);

返回值

返回具有鍵值對的物件。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = "http://www.example.com?section=blog&id=45#comments";
            var obj = str.parseQuery();
            alert ( "obj.section :  " + obj.section );
            alert ( "obj.id :  " + obj.id );
            
            var str = "tag=ruby%20on%20rails";
            var obj = str.parseQuery();
            alert ( "obj.tag:  " + obj.tag );

         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_string_processing.htm
廣告