这是我的简单代码HTML,但它不适用于我
<html lang="en">
<head>
<title>Test</title>
<script type="text/javascript">
function getdata() {
document.getElementById("page").innerHTML="Hello";
}
</script>
</head>
<body>
<a id="teachers" href="" name="teachers" onclick="getdata()">Click here </a>
<div id="page" name="takak" class="home">
modify this text
</div>
</body>
</html>
当我点击链接时,我想修改div的内容(id =“page”)。请有人帮帮我吗?
答案 0 :(得分:0)
<script type="text/javascript">
window.onload = function() {
document.getElementById("teachers").addEventListener("click", function(){
document.getElementById("demo").innerHTML = "Hello World";
});
};
</script>
<a id="teachers" href="" name="teachers">Click here </a>
答案 1 :(得分:0)
您必须添加href目的地,例如:&#34;#&#34; (放置#表示它将指向同一页面上的另一个ID或名称,而不是指向外部URL)。它将是:
<a id="teachers" href="#" name="teachers" onclick="getdata()">Click here </a>