问题
I would like to know if there exists a way to modify the attributes of an element (for example a select
) using a JsCmd in lift.
Here the working version I have for now, running the javascript string.
Run("document.getElementById(\"select_id\").setAttribute(\"width\", \"30px\");")
Thanks in advance.
回答1:
You can use the JqJE library included in Lift which provides a programatic wrapper around JQuery.
The following snippet will create a link that will set the width
attribute of #select_id
to 30px
when clicked.
"#link *" #> a( () => JqId("select_id") ~> JqAttr("width","30px"), Text("clickme"))
This code snippet provides a full example: https://gist.github.com/725432
回答2:
You should be able to use a CSS selector in your snippet, like:
"#select_id [width]" #> scala.xml.Text("30px")
That will modify the attribute width
on the element with id select_id
and set it to 30px.
来源:https://stackoverflow.com/questions/12917298/modify-attribute-of-element