我試圖在JavaScript變量中獲取div
的內容。如何在javascript變量中獲取div內容?
我也嘗試了一些代碼:
<html>
<head>
<script>
function data(){
alert();
var MyDiv1 = document.getElementById('newdata')
alert(MyDiv1);
}
</script>
</head>
<body>
<div id="newdata" style="background-color: red; width: 100px;height: 50px;">
1 <!-- The content I'm trying to get -->
</div>
<a href="" onclick="data();">Logout</a>
</body>
</html>
但它不能正常工作。
'變種含量= MyDiv1.innerHTML;' – Sirko 2014-09-20 10:43:57