如何在JavaScript中写枚举

JavaScript06

如何在JavaScript中写枚举,第1张

var obj = {name:"张三",age:18}for(var key in obj){console.log("key:" + key + ",value:" + obj[key])}//输出:key:name,value:张三和key:age,value:18//这里的可枚举性就是说for的这种写法可以得到这个对象的属性名 var obj1 = {}Object.defineProperties(obj1, {name: {value: "张三",enumerable: false},age: {value: 18,enumerable: false}})for(var key in obj1){console.log("key:" + key + ",value:" + obj[key])}

一, 从controller往视图传递值,controller---->视图

 

1)简单类型,如int, String,直接写在controller方法的参数里,是无法传递到视图页面上的(经测试)。

 

(而用@RequestParam("name")注解,可以从视图上,或地址中加?name=***传递到controller方法里)

 

2)可以用Map<String, Object>,其键值可以在页面上用EL表达式${键值名}得到,

 

3)也可以用Model类对象来传递,有addAttribute(key, value)方法,其键值可以在页面上用EL表达式${键值名}得到,

 

如果用addAttribute(value)这个方法,会将类型名的首字母改成小写后,作为键值名传递过去,例如"ok"在页面上用${string}得到,而一个复合类对象,如User类对象,页面上用${user}得到该对象,用${user.propertyName}得到其属性,这是用Model的一大优势。

例如,model.addAttribute(new User("my姓名","我的爱好有游泳打球"))

这样页面上就能用${user.name}和${user.hobby}打印对应属性

 

     @RequestMapping(value={"/","/hello"})

     public String hello(int id,Map<String,Object> map) {

          System.out.println(id)

          System.out.println("hello")

          map.put("hello", "world")

          return "hello"

     }

   

     @RequestMapping(value="/say")

     public String say(@RequestParam int id,Model model) {

          System.out.println("say")

          model.addAttribute("hello", "value")

          //使用Object的类型作为key,String-->string

          model.addAttribute("ok")

          return "hello"

     } www.2cto.com

1、动态创建元素时,将事件触发方式加入到元素创建中

例如:

document.getElementById('id').innerHTML='<input type="button" onclick="btnClick()" value="aaa"/>'

function btnClick(){

alert('事件触发')

}

2、动态创建元素完成后,重新获取该元素绑定事件

例如:

document.getElementById('id').innerHTML='<input type="button" id="btn" />'

document.getElementById('btn').onclick=function(){

alert('事件触发')

}