🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
![](https://box.kancloud.cn/2ac735de5a1f72657536145e42dfaff2_600x195.png) ~~~ <html> <head> <meta charset="utf-8"> </head> <body> </body> </html> ~~~ ~~~ <script language="javascript"> var o = document.body , userName , btLogin ; //定义变量实现IE6.0和IE7.0兼容。 try { userName = document.createElement("<input>"); // btLogin = document.createElement("<input>"); btLogin = document.createElement("<button>"); } catch (e) { userName = document.createElement("input"); // btLogin = document.createElement("input"); btLogin = document.createElement("button"); } userName.id ="userName"; userName.value ="小明"; o.appendChild(userName); // btLogin.id ="btLogin"; // btLogin.type ='button'; // btLogin.value ="提交"; // o.appendChild(btLogin); btLogin.id ="btLogin"; btLogin.innerText ="提交"; o.appendChild(btLogin); var getUserName = document.getElementById("userName"); var btLogin = document.getElementById("btLogin"); console.log( getUserName.value); console.log( btLogin.value); console.log( btLogin.innerText); btLogin.onclick=function(){ console.log("获取文本信息:"+getUserName.value); } </script> ~~~