我是 JQuery 的新手。我在这里学习 JQuery 基础知识,并认真了解数组在 jQuery 中的工作原理。
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<style>
div { color:blue; }
span { color:red; }
</style>
<script src="jquery-latest.js"></script>
</head>
<body>
<div id="myDiv"></div>
<script>
$(document).ready(function() {
var testArray = ["test1","test2","test3","test4"];
var new_array=[];
var vPool="";
/*i tried but this pushing code dosen't work*/
//pushing values in new_array
$("new_array").push({"test1","test2","test3","test4"});
//fetching the values of new_array
$.each(new_array, function(i, val) {
vPool+=val + "<br />";
});
$('#myDiv').html(vPool);--->
//vPool="";
/*But i tried this code it work fine */
//fetching the values of new_array
$.each(testArray, function(i, val) {
vPool+=val + "<br />";
});
$('#myDiv').html(vPool);
//vPool="";
});
</script>
</body>
</html>
我想知道如何像我们在 PHP 中打印一样打印结构化数组:
echo "<pre>";
print_r($array);