在函数里面声明参数是合法吗??例如:var the_window.src = the_name;(事实是不可以的!但我还是想问问清楚!)<script type="text/javascript">
function Jpg_Image(the_url,the_window,the_name)
{
var the_window = window.open(the_url,'','');
var the_window.src = the_name;
}
</script>

解决方案 »

  1.   

    当然可以,在函数体内使用var语句声明变量时,声明的是局部变量,其作用域是函数体内部,函数被调用时,函数一旦运行结束,局部变量就被销毁;在函数体内不使用var直接声明变量时,声明的是全局变量。你这短短几行代码存在N个问题:
    var the_window.src = the_name; //这行代码报错的原因是你写的变量名是非法的,变量名不能含有点号
    如果你是想修改新打开的窗口的url,那就不应该用var,因为你上面已经声明了一个the_window变量,保存的是对新打开的窗口对象的引用,但是window对象并没有src属性,修改window对象的url要这么写:
    the_window.location.href = the_name;
      

  2.   

    首先我要更正一点..我上面的代码打错了,呵呵,以下是我改正的:
    <script type="text/javascript">
    function Jpg_Image(the_url,the_window_name,new_image)
    {
    var the_window = window.open(the_url,'','');
    var the_window_name.src = new_image;
    }
    </script>我想请教下.........变量the_window_name是Jpg_Image函数的参数。如果我在函数中声明自己函数的参数是否合法??就像上面代码写道【var the_window_name.src = new_image;】。
      

  3.   

    你的意思如果是:the_window_name指的是一个img对象的一个参数,那么the_window.src = the_name就可以了
      

  4.   

    首先我要更正一点..我上面的代码打错了,呵呵,以下是我改正的:
    <script type="text/javascript">
    function Jpg_Image(the_url,the_window_name,new_image)
    {
    var the_window = window.open(the_url,'','');
    var the_window_name.src = new_image;
    }
    </script>
    我想请教下.........变量the_window_name是Jpg_Image函数的参数。如果我在函数中声明自己函数的参数是否合法??就像上面代码写道【var the_window_name.src = new_image;】。