In stead of "spamming" with useless answers, just upvote the answer that helped you.
chillworld ( 2014-09-29 15:28:39 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Dear all,
I can add class through .setSclass("classname")
. How can I remove the sclass
by just specifying the class name? Thanks!
zul with MVVM composer binding:
. . .
<style>.redTextColor { color: red; }</style>
<button id="btnTest" label="test button" onClick="@command('btnTestClick')" />
<label id="labelTest1" sclass="redTextColor" value="text text text text text text"/>
ViewModel:
. . .
@Init
public void initSetup( @ContextParam(ContextType.VIEW) Component view) {
}
@Command
public void btnTestClick(@SelectorParam("#labelTest1") Label labelTest1) {
if (labelTest1 != null) {
String _id = labelTest1.getId();
String _classname = "redTextColor";
String s = "ox_removeClass('" + _id + "'" + "," + "'" + _classname + "')";
System.out.println(s);
Clients.evalJavaScript(s);
}
javascript
/**
* Removes a class name from the zk components sclass.
*
* @param id
* the zk component id.
* @param className
* The class name to remove.
*/
function ox_removeClass(id, className) {
if (id !== null) {
if (jq('$' + id).hasClass(className)) {
jq('$' + id).removeClass(className);
}
}
}
/*
* Adds a class name to zk component sclass.
*
* @param id
* the zk component id.
* @param className
* The class name to remove.
*/
function ox_addClass(id, className) {
if (id !== null) {
if ( ! jq('$' + id).hasClass(className)) {
jq('$' + id).addClass(className);
}
}
}
best Stephan
if you have only one scalss, you can set empty string to remove it. if you have set multiple sclasses, "myclass1 myclass2", you have to get sclass first, split it with space character, filter out one of sclasses, then set result sclass back.
thanks you very helped me
In stead of "spamming" with useless answers, just upvote the answer that helped you.
chillworld ( 2014-09-29 15:28:39 +0800 )editAsked: 2014-09-25 05:49:02 +0800
Seen: 78 times
Last updated: Sep 29 '14
I join the question, I got similar problem. Thanks and wait for answer.
andrew90 ( 2014-09-25 09:50:46 +0800 )editYour question is not clear what is the your exact requirement please specify in details?
sjoshi ( 2014-09-25 12:37:11 +0800 )editterrytornado: thanks for your answer, it is exactly what i want! ^^
alexhk ( 2014-09-26 01:44:05 +0800 )editthan make a vote and close the thread as answered :-)
terrytornado ( 2014-09-26 10:33:26 +0800 )edit