Home > front end >  Js click event
Js click event

Time:10-06

First, I dom programming beginners
I want to increase the form by clicking on a button 100 width, but the writing only click once, bosses teach

CodePudding user response:

Zhi, a variable declared outside a function, and the initialization of 0

CodePudding user response:

Write a click event, binding on the button
Var BTN=document. GetElementById (' find you for the id of the button ')
Var TAB=document. GetElementById (' find form ')
BTN. Onclick=function () {
TAB. Style. The width=TAB. OffsetWidth + 100 + 'px'
}
It is almost click trigger event at a time

CodePudding user response:




<meta charset="utf-8"/& gt;


<style type="text/CSS" & gt;
# box {
Height: 100 px;
Width: 100 px;
background: #000;
Margin: 10 px;
}
</style>
<body>



Var div1=document. GetElementById (' box ');
Var but=document. GetElementsByTagName (" button ") [0];
Var num=100;
But the onclick=function () {
Num=100 num +;
Div1. Style. The width=num + 'px';
}
</script>


CodePudding user response:

Above a few actually all say very understand,
This writing only click once you zhi, because your variables within the method, it is always zhi="100",
Within the methods you can use the debugger to debug, in the browser can press F12 view debug, or use the console. The log (zhi), monitor your parameter values,
  • Related