當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript | 创建对象并通过JavaScript函数在表中显示其内容
生活随笔
收集整理的這篇文章主要介紹了
JavaScript | 创建对象并通过JavaScript函数在表中显示其内容
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
In this example, we created an object named employee with id, name, gender, city, and salary and assigned and displaying the values in the table using JavaScript function.
在此示例中,我們創建了一個名為employee的對象,其對象為id , name , 性別 , city和薪水 ,并使用JavaScript函數分配并在表中顯示值。
HTML & JS:
HTML和JS:
<!DOCTYPE html><html><head><script> var employee ={id:1,name:"pankaj",gender:"male",city:"delhi",salary:34000,show:function(){document.write("<table border=1 >");document.write("<tr>");document.write("<th>Employee Id</th>");document.write("<td>"+this.id+"</td>");document.write("</tr>");document.write("<tr>");document.write("<th>Employee Name</th>");document.write("<td>"+this.name+"</td>");document.write("</tr>");document.write("<tr>");document.write("<th>Gender</th>");document.write("<td>"+this.gender+"</td>");document.write("</tr>");document.write("<tr>");document.write("<th>City</th>");document.write("<td>"+this.city+"</td>");document.write("</tr>");document.write("<tr>");document.write("<th>Salary</th>");document.write("<td>"+this.salary+"</td>");document.write("</tr>");document.write("</table>");}};</script></head><body><script>document.write("<h2>Java Script Objects : Type 2</h2><hr />");employee.show();</script></body> </html>Output
輸出量
翻譯自: https://www.includehelp.com/code-snippets/create-an-object-and-display-its-content-in-a-table-through-javascript-function.aspx
總結
以上是生活随笔為你收集整理的JavaScript | 创建对象并通过JavaScript函数在表中显示其内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fgo福袋多少钱啊?
- 下一篇: mcq 队列_人工智能| AI解决问题|