我该如何做这个工作?我在数组“第三个元素”中有一个空格“John”。jquery在数组中找到一个空格的字符串
看看: http://jsfiddle.net/hyHFT/
<style>
div { color:blue; }
span { color:red; }
</style>
<div>"John" found at <span></span></div>
<div>4 found at <span></span></div>
<div>"Karl" not found, so <span></span></div>
<script>var arr = [ 4, " Pete", 8, " John" ];
$("span:eq(0)").text(jQuery.inArray("John", arr));
$("span:eq(1)").text(jQuery.inArray(4, arr));
$("span:eq(2)").text(jQuery.inArray("Karl", arr));
</script>
感谢 格拉西亚斯! 埃尔龙舌兰
是消除空间? – 2011-06-16 23:14:00