javascript代码在和
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form name="form">
<input type="button" name="b1" id='b1' value="text" />
<script language="javascript">
var b1 = document.getElementById('b1');
/* 其中$str变量可以为你服务器返回的变量*/
$str = 'hello world';
if(b1.attachEvent){ //MSIE 方法
b1.attachEvent("onclick", function(){alertMsg($str)});
}else if(b1.addEventListener){ // W3C方法
b1.addEventListener('click',function(){ alertMsg($str)});
}
function alertMsg(s){
alert(s);
}
</script> </form>
</body>
</html>
我的问题是:如果吧javascript代码放在head区,不会出现任何效果