Modify attribute of element

早过忘川 提交于 2019-12-11 11:19:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!