Skip to content

Instantly share code, notes, and snippets.

@Centaur
Forked from yangbajing/gist:5010405
Created February 22, 2013 03:14
Show Gist options
  • Save Centaur/5010463 to your computer and use it in GitHub Desktop.
Save Centaur/5010463 to your computer and use it in GitHub Desktop.
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) + ")"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment