由於某些原因,我必須通過javascript函數分配javascript代碼,如下面的代碼。通過javascript函數分配javascript代碼
<html>
<head>
<script>
window.onload = init();
function init(){
document.getElementsByName('content')[0] = alert('LOL');
}
</script>
<script type="text/javascript" name="content">
</script>
</head>
<body>
</body>
</html>
頁面加載後,預期結果應該像下面
<html>
<head>
<script type="text/javascript">
alert('LOL');
</script>
</head>
<body>
</body>
</html>
然而,alertbox不顯示。有沒有人可以幫助我?
爲什麼要這樣?你想要完成什麼? – Sjoerd 2012-02-21 15:47:07
確定這裏真正發生了什麼? – Esailija 2012-02-21 15:47:38
提高您的樣本質量,腳本標記和getElemen *** t *** sById中的錯誤。我們無法編輯這麼幾個字符... – 2012-02-21 15:49:17