本文實例講述了Javascript中With語句用法。分享給大家供大家參考。具體如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>With語句(類似於VB中的)</title> <script type="text/javascript"> function Student(name, age) { this.name = name; this.age = age; } var stu = new Student('羅納爾多', 36); with (stu) { //With語句(類似於VB中的),用於簡化代碼 alert("Name:" + name + ",Age:" + age); } </script> </head> <body> </body> </html>
希望本文所述對大家的javascript程序設計有所幫助。