双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

input 的onclick事件 为什么不能用

郭薇薇_ 郭薇薇_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.test{
background-color: blue;
}
</style>

</head>
<body>
<input type="button" onclick="showMsg()" value="调用Ajax显示内容" />
<span id="msg"></span>

<script type="text/javascript">
var xmlHttp;
function createXMLHttp(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function showMsg(){
createXMLHttp();
xmlHttp.open("POST","content.html");
xmlHttp.onreadystatechange= showMsgCallback;
xmlHttp.send(null);
}
function showMsgCallback(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status ==200){
var text =xmlHttp.responseText;
document.getElementById("msg").className="test";
document.getElementById("msg").innerHTML=text;
}
}
}
</script>
</body>
</html>
...全文

相关推荐

评论 20
收藏 已收藏
分享
返回顶部
郭薇薇_
Web 开发 81,108 成员 341,721 内容