Home > front end >  About object-oriented ask for help! Hope to be able to get some, thank you!
About object-oriented ask for help! Hope to be able to get some, thank you!

Time:10-26

I want to by the object-oriented thought click number of accumulation, but strength is limited, want to ask next everybody, I think whether reality
Purpose: a lot of news on the same page, every news here has three said the number of regions, each region has a tag number display, a tag is a + 1, + 1, just click on the previous number will automatically add 1, because there are many of these areas, so I want to encapsulate a function to realize, thought of the object-oriented
Numbers in front of my idea is: will the label and the back of the + 1 label as a parameter, use a function to achieve the above operation, but want to for a long time did not realize, did find alternative methods at present, but I still want to know my this idea can be implemented? Thank you for your attention!

CodePudding user response:

 




The function add1 (id) {
Document. The getElementById (id). InnerText++;
}
</script>

CodePudding user response:

Thank you thank you! Skills learned! Happy, attach my stupid way!

CodePudding user response:




<meta charset="utf-8">


<style type="text/CSS" & gt;
The dd {
Background - color: blue;
}
# ce {
border: 1px solid red;
Margin - bottom: 15 px;
Width: 200 px;
}
</style>
<body>
56

Wow. & lt; The button & gt; 500 & lt;/button>

56

Wow. & lt; The button & gt; 500 & lt;/button>


Var btn_zan=document. QuerySelectorAll (' btn_zan ')
The function dianZan (a) {
//for thumb up button
Atul gawande at the var z=etAttribute (' class ')
If (z=='btn_zan') {
Anderson nnerHTML=parseInt (Anderson nnerHTML) + 1;
A.c lassName='btn_zan dd'
//get the parent element and the parent element to change the elements and then operate
//focus on parentNode and getElementsByClassName (' pp ') [0]
Var. CCC=Amy polumbo arentNode getElementsByClassName (' pp ') [0];
CCC. InnerHTML=parseInt (CCC) innerHTML) + 1
} else {
Anderson nnerHTML=parseInt (Anderson nnerHTML) - 1;
A.c lassName='btn_zan'
//get the parent element and then operate
Var NNN=Amy polumbo arentNode. GetElementsByClassName (' pp ') [0];
NNN. InnerHTML=parseInt (NNN. InnerHTML) - 1
}
}
//bind event! Use this to obtain the current object
for(var i=0; iBtn_zan [I] onclick=function () {
DianZan (this)
}
}
</script>

CodePudding user response:

Many examples foundation is bad, bad! Thank you
  • Related