Perhaps when you use jquery mobile, you will often see the use of Data-role, Data-theme, and so on, such as: The following code to achieve the effect of the header:
[HTML]
<div data-role= "Header" >
</div>
Why write a data-role= "header" can be achieved at the bottom of the black, Text center display effect?
This article provides one of the simplest ways to achieve this by giving you an intuitive understanding of these usages.
We write an HTML page, customize a data-chb= "header" property, want to have this attribute of the div area background color is black, the text is white, center display; the div with no Data-chb custom attributes is displayed by default, with the HTML code as follows:
[HTML]
<body>
<div data-chb= "Header" >
</div>
<br/>
<div>
I do not use DATA-CHB custom attributes, how to show how to show;
</div>
</body>
To achieve the "background color is black, text is white, centered display" effect, we define the following CSS:
[CSS]
<style>
. ui_header {
Text-align:center;
Color:white;
border:1px solid #000;
}
</style>
Then we implement the following JS method to dynamically add CSS definitions to the page load, changing the display style of the div with the Data-chb attribute:
[JavaScript]
<script type= "Text/javascript" >
Window.onload=function () {
var elems = document.getelementsbytagname ("div");
if (elems!=null&&elems.length>0) {
var length = Elems.length;
Traverse All div controls
for (Var i=0;i<length;i++) {
var elem = elems[i];
Gets the custom properties of the control
var customattr = Elem.dataset.chb;
You can also get custom properties in the following ways
var customattr = elem.dataset["ChB"];
If it is our predefined header value, it means that we need to handle
if (customattr== "header") {
Add Style
Elem.setattribute ("Class", "Ui_header");
}
}
}
}
</script>
HTML5 Customizing the Data property