weixin_33714884 2014-03-05 11:54 采纳率: 0%
浏览 32

jQuery和Ajax脚本

So i have a jQuery script that i should explain it line by line, i already do that and i want to make sure that is correct, so this is my script :

 //Here we use the jQuery selector ($) to select the servers_id which is located into  
//the delivers_id and we attaches a function to run when a change event occurs

 $("#delivers #servers").change(function(){

//Here we look if the servers_id value was changed and the value is different of 0

    if($(this).val() != '0') {

//Here we create a new variable sid and we stored the servers_id value in it
        var sid = $("#delivers #servers").val();

//Here we use the Ajax $.get to get the sid value and send it by Ajax request then 
//we set the data into the o_vmats_id html and empty the vmtas_id
        $.get("/deliverability/get_vmtas/" + sid,
        function(data) { $('#o_vmtas').html(data); $('#vmtas').html(''); });
    } 

//Here the else statement, we select the vmtas_id and set the html content like in the code (value=0)
//and empty the o_vmtas_id html content
    else { $('#vmtas').html('<option value="0">All Classes</option>');  

     $('#o_vmtas').html(''); }
});

so please if someone has any remark i will be very appreciative

  • 写回答

1条回答 默认 最新

  • weixin_33688840 2014-03-05 11:59
    关注

    You're looking for the #servers element twice, no need for that. You can and should cache items that are going to be looked up more than once, so store that element in a var at the very beginning.

    Other than that... there's not much to it, other than you wouldn't actually need much jQuery to do this :)

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊