高手近来帮帮忙,简单问题
<html>
<head>
<title>
test
</title>
<script language= "javascript ">
var obj;
var ss;
function aaa(obj)
{
obj= "sssssss "
alert(obj)
ss=obj;
}
function bbb()
{
alert(obj);
alert(ss);
}
</script>
</head>
<body>
<form id= "form1 ">
<input type= "button " id= "but1 " value= "333 " onclick= 'aaa( "sss "); '/>
<input type= "button " id= "ttt " value= "444 " onClick= "bbb(); "/>
</form>
</body>
</html>
先点击aaa(),然后点击bbb()得不到alert(obj)的值,但是赋值给ss才可以得到,谢谢。
------解决方案--------------------var obj;
var ss;
function aaa(obj)
{
obj= "sssssss " //这一句改的是function的参数,不是全局变量,要改全局变量请用window.obj= "sssssss "
alert(obj)
ss=obj;
}