如何用JS制作以下网页

JavaScript027

如何用JS制作以下网页,第1张

这样的有几种写法,一个就是发送请求给后台,传的数据是邮箱,然后获取用户名,域名,顶级域名,然后渲染到页面上,但是这得后台配合,第二个就是自己声明假的数据,就是一个数组,里面有多个对象,比如:

<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>")

运行结果: