我只是这方面的新手。我有通过 JavaScript 函数生成 div 的代码。div 创建成功,但在几秒钟内消失。
html:
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<script type="text/javascript" src="../jQuery.js"></script>
<script type="text/javascript" src="music.js"></script>
</head>
<body>
<div id="formDiv">
<form name="noteSelectorForm" accept-charset=utf-8>
<Select name="noteSelector">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
<option value="G">G</option>
</select><br>
<input type="radio" name="Note" value="Nil" checked>Nil<br>
<input type="radio" name="Note" value="Sharp">Sharp<br>
<input type="radio" name="Note" value="Flat">Flat<br>
<button onClick="keySelectTwo()">Submit</button>
</form>
<div id="printSelectedNote">
</div>
</div>
</body>
Javascript:
var keySelectTwo = function(){
var x = document.noteSelectorForm.noteSelector.value;
var travelerInfo = '<div>'+x+'</div>';
var first = 0;
if(document.getElementById("printSelectedNote").child){
alert("test");
}
else{
document.getElementById("printSelectedNote").innerHTML += travelerInfo;
}
};
有什么建议吗?谢谢。