The code is very simple, mainly to provide you with a way of thinking, but also learning JavaScript for so long a small practicing.
Chained programming is the use of multiple operations (multiple lines of code) through the dot number "." Link together to become a code. Chain code usually requires a return value for the operation, but for many operations mostly void, nothing returns, so it is difficult to link up, of course, there are solutions, may not be very elegant. The new idea of chained programming has been used in jquery
Copy Code code as follows:
<span>hello,world! </span>
<script type= "Text/javascript" >
Jq = function (tagName) {
var Tagarr = document.getElementsByTagName (tagName);
var ret = {
Tag:tagarr,
Css:function (attribute, value) {
for (var i = 0; i < this.tag.length; i++) {
This.tag[i].style[attribute] = value;
}
return this;
}
}
return ret;
}
Window.onload = function () {
JQ ("span"). CSS ("Color", "red")
. CSS ("Border", "1px solid green")
. css ("padding", "10px");
}
</script>
If you want to ask, leave a message, we will make progress together.