亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

input 文本框輸入內容回車后 在ul里增加li顯示

Original 2019-01-24 17:12:55 385
abstract:<!DOCTYPE html> <html> <head> <title>demo11 聊天室原理</title> </head> <body> <input type="text" name="info" onk
<!DOCTYPE html>
<html>
<head>
	<title>demo11 聊天室原理</title>
</head>
<body>

	<input type="text" name="info" onkeypress="addtxt()" id="infotxt">	
	<ul>

	</ul>
	<p>text01</p>
	<p>text02</p>
	<p id="tt">text03</p>
	<p>text4</p>
	<p>text5</p>				
	<input type="button" value="css selector" onclick="doit()">
	<input type="button" value="DOM tree" onclick="doit1()">
	<input type="button" value="create html" onclick="doit2()">
<body>
<script type="text/javascript">
	function addtxt()
	{
			if (event.keyCode == 13) {
				 var  vt1 = document.querySelectorAll("input");
				 var vsz = vt1[0].value;

				 if (vsz.length > 0)
				 {
					  var ul = document.getElementsByTagName('ul')[0];
					  var li = document.createElement('li');	 
					 li.innerHTML = vsz;	 
					 ul.appendChild(li);	 
			         vt1[0].value = '';	 				  
				 }
				 //console.log(vt1[0].value)				
		        //alert(infotxt.text);
		    }
	}

	function doit2()
	{
		var vtt = document.querySelector("#tt");
        var mul = document.createElement("ul");
        var vhead =document.createElement("span");
        var vinput =document.createElement("input");
        vhead.innerText ="I am new span words";

        mul.innerHTML ="<li>new li item</l,i>";
		//document.body.appendChild(mul);
		vtt.appendChild(mul);

		vinput.setAttribute('type', 'text');  //定義類型是文本輸入
	    //document.getElementById('form').appendChild(input ); //添加到form中顯示


		vtt.insertBefore(vinput,null);
		vtt.insertBefore(vhead,mul);
	}
	   // console.log(document.childNodes);
	function doit1()
	{
		console.log(document.nodeType +"\r\n"+document.nodeName+"\r\n"+document.nodeValue);
		console.log(document.childNodes+document.childNodes[1]);
	}

    //
	function doit()
	{
		var vt2,vt3,vt4;
		var  vt1 = document.querySelectorAll("p");
		console.log(vt1);
		vt1[0].style.backgroundColor="red";
		console.log(vt1.item(1));
        vt1.item(1).style.color="blue";

        vt2 = document.querySelector("#tt");
        console.log(vt2);
        vt2.style.fontSize = "30px";
       // vt2 = 
		//alert("hello");
	}
</script>
</html>


Correcting teacher:天蓬老師Correction time:2019-01-24 17:19:00
Teacher's summary:寫得很有創(chuàng)意: vt2 = document.querySelector("#tt");, 這樣的變量定義, 以后不要再用了,應該改成: var vt2 = document.querySelector("#tt"); 以防止生成過多的全局變量,污染全局環(huán)境

Release Notes

Popular Entries