$().ready ( function(){ var array = [1,2,3,4,5,6,7,8,9]; var filterarray = $.grep(array,function(value) { return value > 5; // Filter out }) that are greater than 5; for(var i=0;ialert(filterarray[i ]); } for (key in filterarray){ alert(filterarray[key]); } } );
$(). ready( function(){ var anArray = ['one','two','three']; var index = $.inArray('two',anArray); alert (index);//Returns the key value of the value in the array, returns 1 alert(anArray[index]);//value is two } );
$() .ready( function(){ var strings = ['0','1','2','3','4','S','6']; var values = $.map(strings,function(value){ var result = new Number(value); return isNaN(result) ? null:result;//isNaN:is the abbreviation of Not a Number } ); for (key in values) { alert(values[key]); } } );
var json = [{dd :'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i=0,l=json.length;i< l;i ){ for(var key in json[i]){ alert(key ':' json[i][key]); } }
js traversal and parsing json object 2
has the following json object: var obj ={"name":"Feng Juan","password":"123456″,"department":" Technology Department","sex":"female","old":30}; Traversal method:
for(var p in obj){ str = str obj[p] ','; return str; }
The following is an example to illustrate the specific implementation method
The way JQuery gets the object
$('#id'): through the id of the element $('tagName '): Pass the tag name of the element $('tagName tagName'): Pass the tag name of the element, eg: $('ul li') $('tagName#id): Pass the id and Tag name $(':checkbox'): Get all elements whose input type is checkbox': Eg: value="imperial "/>
$('span[price] input[type=text]'): Get the following input element < input type="text" name="imperial.quantity" disabled="disabled" value="1"/>
$('div',$(this) .parents('div:first')): Get the first div node above the div (at least the parent node) $('~ span:first',this): locates the first sibling of this that's a element.
< script type="text/javascript"> $(function(){ $('#loadButton').click(function(){ $.getScript(//In Firefox/3.0. An error will appear in 1 (syntax error, defined variables do not work, ff2 is fine) 'new.stuff.js'//, function(){$('#inspectButton').click()} ); }); $('#inspectButton').click(function(){ someFunction(someVariable); test() }); });
function test() { alert('test'); } alert("I'm inline!"); var someVariable = 'Value of someVariable'; function someFunction(value) { alert(value); } function test() { alert('test'); }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn