JQuery函数众多,避免学过又忘记,慢慢积累,慢慢更新:
1.prepend(): 在element的开始位置加入内容
1 function processData(data){
2 if(data == 'pass'){
3 $('#content').html('<p>You have successfully logged on!</p>');
4 }else{
5 $('#formwrapper').prepend('<p id="fail">Incorrect login information. Please try again</p>');
6 }}
7 }
2.$.getJSON():获取JSon对象,语法$.getJSON('xxx.php',data,callback);
1 $.getJSON('contacts.php','limit=2',processContacts);
2 function processContacts(data){
3 var infoHTML = '';
4 //loop through each object in the JSON data
5 $.each(data,function(contact,contactInfo){
6 infoHTML += '<p>Contact: ' + contactInfo.firstName;
7 infoHTML += ' ' + contactInfo.lastName + '<br />';
8 infoHTML += 'Phone: ' + contactInfo.phone + '</p>';
9 });
10
11 $('#info').html(infoHTML);