在liftweb 中扩展一个类似 jQuery的方法:$("...").XXX() 和 jQu...

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


import scala.xml.NodeSeq

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

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(" + key.encJs + ")"
  }

}

你可能感兴趣的:(js,jquery,scala,lift)