在liftweb中扩展一个类似jQuery的方法

先上代码,文字稍后再补!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import scala.xml.NodeSeq

import net.liftweb.http.js._
import net.liftweb.http.js.jquery._

def $(exp: String): jQuery = $(JE.Str(exp))

def $(exp: JsExp): jQuery = jQuery(exp)

case class jQuery(exp: JsExp) {
val jq = JqJE.Jq(exp)

@inline
def value(value: JsExp) = (jq ~> JqJE.JqAttr("value", value)).cmd

@inline
def value() = (jq ~> JqJE.JqGetAttr("value")).cmd

@inline
def html(content: NodeSeq) = (jq ~> JqJE.JqHtml(content)).cmd

@inline
def html() = (jq ~> JqJE.JqHtml()).cmd

@inline
def remove() = (jq ~> JqJE.JqRemove()).cmd

@inline
def attr(key: String, value: JsExp) = (jq ~> JqJE.JqAttr(key, value)).cmd

@inline
def attr(key: String) = (jq ~> JqJE.JqGetAttr(key)).cmd

@inline
def removeAttr(key: String): JsCmd =
(jq ~> JqRemoveAttr(key)).cmd

// 更多方法实现 ................................................................

case class JqRemoveAttr(key: String) extends JsExp with JsMember {
def toJsCmd = "removeAttr(" + JE.Str(key) + ")"
}

}
分享到