日期:2014-05-16  浏览次数:20373 次

为什么第二种方法有错误?求指点
创建一个button按钮,当点击这个按钮时,打开一个新的窗口,第一种方法能顺利执行,而为什么第二种怎么说有语法错误呢?

第一种方法是下面这样的:
<html>
<head>
<title>test html</title>

<script type="text/javascript">
function newWindow(){
window.open("test1.html","new","height=50,width=50");
}
</script>
</head>

<body>

<form action="" method="post" name="form1">
<input type="button" name="button1" value="new window" onClick="newWindow()">
</form>

</body>

</html>



第二种方法如下:

<html>
<head>
<title>test html</title>

<script type="text/javascript">


</script>

</head>
<body>


<form action="" method="post" name="form1">
<input type="button" name="button1" value="new window" onClick="window.open("test1.html","new","height=50,width=50");">
</form>



</body>

</html>

为什么第二种方法提示语法错误呢?



------解决方案--------------------
改成这样吧
JScript code

<html>
   <head>
      <title>test html</title>
   </head>
   <body>
      <form action="" method="post" name="form1">
         <input type="button" name="button1" value="new window" onClick="javascript:window.open('test1.html','new','height=50,width=50');">
      </form>
   </body>
</html>

------解决方案--------------------
确实,很基础的问题,要么转义要么用单引号