JavaScript | 创建对象并通过JavaScript函数在表中显示其内容
2020-08-03 08:36
791 查看
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>[/code]
Output
输出量
相关文章推荐
- 前端学习笔记三:JavaScript(1)初识js(前提知识储备+警告框+变量与常量+访问HTML元素+显示js值+调用外部js文件+声明创建对象+在js里获取HTML对象并在其内容里插入值)
- [转载内容]动态创建菜单,menustrip,根据权限显示菜单,控制菜单可用,反射,给窗体传值,反射对象传值,public static Object CreateInstance ( Type type, params Object[] args )
- 通过JavaScript创建Qml对象
- 读取XML数据时,已超过最大字符串内容长度配额(8192)。可以通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxStringContentLength属
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。【轉】
- JavaScript 仿LightBox内容显示效果 创建个LightBox.htm文件粘进去,直接查看效果
- java 和 JavaScript都可以在创建一个对象时,就可以通过这个对象调用相应方法
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。
- WCF:读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。
- JavaScript 通过function创建对象的思考
- 通过JavaScript创建Qml对象
- javascript中创建对象,并序列化为json,通过$.ajax的提交json数据到后台方法,取值为null的问题
- Swift中tableView加载通过xib创建的headerView时,无法显示xib视图内容.
- 使用web服务时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLen
- IE6通过点击 <a href="javascript:void(0);"></a>方式动态创建iframe无法显示
- IE6通过点击 <a href="javascript:void(0);"></a>方式动态创建iframe无法显示
- 创建一个Session对象,用javascript弹出内容
- ndk多线程需要获取JNIEnv 或c通过类名+包名创建对象使用如下方法
- javaScript对象和属性的创建方法
- javascript 创建对象