I always think that if the JavaScript could do this, how can we do with the jQuery??
At first, we must understand how to declare a One-Dimensional Array with the jQuery:
var tempArray = function() { var virArray = new Array(3); $.each(virArray, function(index, context) { virArray[index] = "Hello!! World!! \n"; return; }); return virArray; };And, we could read the array contents by $.each() function, too:
$.each(tempArray(), function(index, context) { var strTemp = null; strTemp = "tempArray[" + index + "]: " + context + "\n"; return; });The total solution as below:
<!DOCUMENT html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.prg/TR/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="./js/jQuery/jquery-1.8.3.min.js"></script> <script type="text/javascript" language="JavaScript"> var tempArray = function() { var virArray = new Array(3); $.each(virArray, function(index, context) { virArray[index] = "Hello!! World!! \n"; return; }); return virArray; }; </script> </head> <body> <div id="DebugConsole"></div> </body> <script type="text/javascript"> (function($) { $(window.document).ready(function() { var strTemp = null; $.each(tempArray(), function(index, context) { strTemp = "tempArray[" + index + "]: " + context + "<br/>"; $("#DebugConsole").append(strTemp); return; }); return; }); return; })(jQuery); </script> </html>
(To be continue....)
沒有留言:
張貼留言