原型 - inspect() 方法



此方法返回字串的除錯版本,即由單引號或雙引號包裹起來,並轉義反斜槓和引號。

語法

string.inspect([useDoubleQuotes = false]);

返回值

返回字串的除錯版本。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = 'I\'m so happy.';
            alert( "Check without inspect :" + str ); 
            alert( "First Check :" + str.inspect() );
            alert( "Second Check :" + str.inspect( true ) );
         }
      </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
廣告
© . All rights reserved.