<strong>Let’s look at the error example first</strong> <br>Html code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="65151" class="copybut" id="copybut65151" onclick="doCopy('code65151')"><u>Copy the code</u></a></span> The code is as follows:</div> <div class="codebody" id="code65151"> <br><body> <br><input id="certid" type="text" value="123456" > <br><input id="btn" type="button" value ="button" onclick=""> <br></body> <br> </div> <br>Javascript code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="56865" class="copybut" id="copybut56865" onclick="doCopy('code56865')"><u>Copy code</u></a></span> The code is as follows: </div> <div class="codebody" id="code56865"> <br><script> <br>function show(value) <br>{ <br>alert(value); <br>} <br><br>btn.onclick = show(certid.value); <br><script> <br> </div> <br>There is an error in executing the above code, because the sentence show(certid.value) is executed directly show method, but did not correctly assign this method object to the btn.onclick event. <br><strong>If we change it to this</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="34839" class="copybut" id="copybut34839" onclick="doCopy('code34839')"><u>Copy code</u></a></span> The code is as follows: </div> <div class="codebody" id="code34839"> <br>btn.onclick = show; <br> </div> <br>The parameters cannot be passed. <br>So the correct code should be written like this , we add a parameter to see it more clearly: <br>Html code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="65151" class="copybut" id="copybut65151" onclick="doCopy('code65151')"><u>Copy code</u></a></span> The code is as follows: </div> <div class="codebody" id="code65151"> <br><body> <br><input id="certid" type="text" value="123456" > <br><input id="btn" type="button" value= "button" onclick=""> <br></body> <br> </div> <br>Javascript code<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="55797" class="copybut" id="copybut55797" onclick="doCopy('code55797')"><u>Copy code</u></a></span> The code is as follows: </div> <div class="codebody" id="code55797"> <br><script> <br>function show(value1,value2) <br>{ <br>alert(value1 "," value2); <br>} <br><br>var i = 10; <br>btn.onclick = function(){ <br>show(certid.value,i); <br>}; <br><script> <br> </div> <br>This enables dynamic assignment of values to the onclick event handle and supports the passing of parameters.