<input type="text" placeholder="请输入邮箱">
<button>开始分析</button>
<div>
用户名:<span class="username"></span></br>
域名:<span class="domain"></span></br>
顶级域名:<span class="top-domain"></span>
</div>
<script type="text/javascript">
var arr = [{email:"xx@163.com",username:"zhangsan",domain:"hao123",topDomain:".com"},{email:"yy@qq.com",username:"lisi",domain:"baidu",topDomain:".com"},{email:"zz@msn.com",username:"wangwu",domain:"taobao",topDomain:".com"}]
var inp = document.getElementsByTagName("input")[0]
var btn = document.getElementsByTagName("button")[0]
var username = document.getElementsByClassName("username")[0]
var domain = document.getElementsByClassName("domain")[0]
var topDomain = document.getElementsByClassName("top-domain")[0]
btn.onclick = function() {
var val = inp.value
username.textContent = ""
domain.textContent = ""
topDomain.textContent = ""
for (var i=0i<arr.lengthi++) {
if (val == arr[i].email) {
username.textContent = arr[i].username
domain.textContent = arr[i].domain
topDomain.textContent = arr[i].topDomain
}
}
}
</script>
js输出html中表格的方法如下:
document.write("<table border=1 >")
for(i=1i<=ri++)
{
document.write("<tr>")
for(j=1j<=cj++)
document.write("<td>"+Math.pow(j,i)) //输出数组
document.write("</tr>")
}
document.write("</table>")
运行结果: