javascript - create css class on the fly in codebehind -
I have a search page, which is used on many sites with many 'themes' on my site. I have some devices that can change based on radio button selection (whether they are enabled or not). With Java, I can fix this by changing Div's CSS class on the fly.
However, these topics may have to be changed in potentially, and background color comes from the database when the page is created. Right now I do this in C # codebehind:
string bgStyle = "background-color:" + theme.searchTextHeaderColor + ";"; OwnSearchHeader.Attributes.Add ("style", bgStyle); In Javascript I need to change this color to disable it, and when the user clicks back on this device, then I can re-enable it by turning it back to its original color.
Have to do. But since I knew the colors behind the code, I do not know what it was in javascript. So, in my opinion, to create a CSS class in the resulting HTML page, when the page is filled with background color that I need, then I could simply switch from javascript to a divined and divided class. But I'm not sure how to do this.
Alternatively, I can make a hidden element, provide it the 'enabled' style, and it uses it as context in JavaScript while enabling my div. It seems like a hack, but perhaps its easiest way I'm still new to doing so, so I appreciate any suggestions thank you for input!
So my idea was to create a CSS class in the resultant HTML page when the page background color I'm loaded with needs. Then I could simply switch from javascript to divinated and divided classes. But I'm not sure how to do this.
Yes, this is Acer; Do it. The & lt; Head> gtc:
in and
& lt; Style & gt; & Lt ;! -. Divinated {background color: & lt;% = theme.searchTextHeaderColor%>; } .divDisabled {background-color: gray; / * Or wtv * /} - & gt; & Lt; / Style & gt;
You can also put it in an external CSS file, which can be a good idea.
Then type some javascript to add / remove the class attribute (I 'is going to ask you that;;))
var owners searchdifference = document.getElementById ( "& Lt;% = owner search store. Client ID%> & gt;"); // Change the class attribute in `divDisabled` var newClassAttribute = ownersearchheader.getAttribute (" square "). (/ \ BdivEnabled \ b /, "divDisabled")) ownersearchheader.setAttribute ("class", newClassAttribute); // ... or // // change the square attribute in `divEnabled` var newClassAttribute = ownersearchheader.getAttribute (" class "). (/ \ BdivDisabled \ b /, "divEnabled"). Traceblot.setAttribute ("class", newClassAttribute);
This is actually a mouth, therefore, as Hyder says, you might want to use jQuery, which easily read addClass ()
, Remove class ()
and toggleclass ()
methods.
Comments
Post a Comment