像jquery的ajax类是如何编写的,看源代码就是看不懂。$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
}); 这种结构如何编写的?

解决方案 »

  1.   

    jQuery 这样的框架用的是所谓的“散列”编程,类似的还有比较有名气的Prototype、ExtJS。
    下面给出一个例子:<select id="selectId" style="width:120;"></select><script>
    var fillSelect = function(selectDom,jsonArray){
    if(jsonArray.constructor !== Array){
    alert('argument is not a Array!');
    return;
    }
    for(var i = 0, j = jsonArray.length; i < j ; i++){
    selectDom.options[i] = new Option(jsonArray[i].text,jsonArray[i].value);
    if(jsonArray[i].selected){
    selectDom.options[i].selected = true;
    }
    }
    };
    window.onload = function(){
    var selObj = document.getElementById('selectId');
    fillSelect(selObj,[{
    text: '北京市',
    value: 101
    },{
    text: '河北省',
    value: 102
    },{
    text: '天津市',
    value: 103,
    selected: true
    }]);
    };
    </script>