How to pass value of inner function to outer function in javascript? -
this question has reply here:
why variable unaltered after modify within of function? - asynchronous code reference 6 answersi want pass value of inner function outer function. want alter value of a=2 when treeimage clicked. here code, doing wrong?
<script type="text/javascript" language="javascript"> sys.webforms.pagerequestmanager.getinstance().add_endrequest(endrequesthandler); function endrequesthandler(sender, args) { var a; var treeviewdata = window["<%=treeview2.clientid%>" + "_data"]; var treeview1 = $('#<%= treeview2.clientid %>'); var treenodes = treeview1.find("div[id$=nodes]"); var treeimages = treeview1.find("img").not("img[alt=\'\']"); treeimages.click(function () {//if image clicked should 2 = 2; }); if (treeviewdata.selectednodeid.value != ""&&a!=2) { $find("dde").hide(); } else { $find("dde").show(); } } </script>
put var a
outside endrequesthandler()
.
what you're doing in code closure, it's pointless closure @ that. function treeimages.click
"closing around" a
variable, given code doesn't deed different if var a
within treeimages.click
function.
javascript
No comments:
Post a Comment