How to implement a closure in jQuery [on hold]

<p>I don't know much about jQuery. Here I am trying to implement a closure to attach a click event to each anchor tag so that each of them will alert a certain number once blicked. But I am getting the following error:</p><blockquote><pre><br /><code>SyntaxError: missing ) after argument list<br /><br /><br />};})(i);<br /></code><br /></pre></blockquote><p>can anyone help me with this problem?thanks :)</p><p>Code:</p><pre><br /><code><div id='pageBox'><br /> <ul id='pageContainer'><br /> <?php for($i=1;$i<=$pagenum;$i++){?><br /> <li><a href=''><?php echo $i;?></a></li><br /> <?php }?><br /> </ul><br /> </div><br /><script><br />for(i=1;i<=<?php echo $pagenum;?>;i++){<br /><br /> $('#pageContainer li a').click((function(i){return function(event){<br /> event.preventDefault();<br /> alert(i);<br /> };})(i);<br /> );<br /><br />} <br /></code><br /></pre><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525506/how-to-implement-a-closure-in-jquery">http://ift.tt/1QXmsX9</a></h2>

Nhận xét

Bài đăng phổ biến từ blog này

Align div to bottom of the page in bootstrap

Align elements inside an tag vertically

Javascript is unable to stop page loading