JQuery常用标签

标签名: $('p')  会取得文档中所有的段落
ID: $('#some-id') 会取得文档中所有对应的some-id ID的一个元素
类:$('.some-class') 会取得文档中所有带some-class类的所有元素
 
 
$(document).ready(function() {
  $('#switcher-large').bind('click', function() {
    $('body').addClass('large');
  });
});
 
 
//遍历数组 data数组
jQuery.each(data, function(n, value) {
  alert(n);
});
 
 
// 根据id修改属性 已图片img为例
var imgIdStr = "#" + imgId; // 修改图片的id
jQuery(imgIdStr).attr("src","/images/duihao.jpg");
 
// 每5秒刷新一次
window.setInterval(function () {flushAppList()}, 5000);
 
 
// 修改span里的属性
jQuery("#spanshowTime").html("eeeeee");
<span id="spanshowTime">ssasa</span>
 
// select
var appId = jQuery("#app_id").find('option:selected').val();// 得到下拉菜单的选中项的值(360 ie 有时会出现不兼容,如默认不选取时,不能获得值)
var checkValue = jQuery("#select_id").val();  //获取Select选择的Value
 
// input text 添加值
$("#appId").attr("value", appId);
 
 
        // 刷新应用列表,获得最新的状态  Ajax
    function flushAppList(){
      jQuery.ajax({
        cache : false,
        type : "GET",
        dataType : 'json',
        url : "$rc.contextPath/fulshAppAjax?pageSize=$paginator.pageSize&pageNumber=$paginator.pageNumber&appBackPageNo=$paginator.pageNumber",
        success : function(data) {
          if(data != null){
            jQuery.each(data, function(n, value) {
                var appId = value["id"];
                var status = value["status"];
                var showTime = value["showTime"];
                var imgId = "#img" + appId; // 修改图片的id
                var spanshowTimeId = "#spanshowTime" + appId; // 最后监测时间id
                
                if(status){
                  jQuery(imgId).attr("src","/images/duihao.jpg").attr("title","正常");
                }
                else{
                  jQuery(imgId).attr("src","/images/cuohao.jpg").attr("title","异常");
                }
                
                jQuery(spanshowTimeId).html(showTime); // 修改最后监测时间
            });
          }
        }
      });
    }
 
 
/**
 * 发送自定义命令  ajax提交中文
 * @param appId 应用id
 * @param unitId 单元id
 * @param command 自定义命令
 */
function sendCommand(appId, unitId, command) {
    jQuery.ajax({
        cache : false,
        type : "POST",
        dataType : 'json',
        url : "$rc.contextPath/sendCustomizeCommandAjax?app_id=" + appId + "&unit_id=" + unitId,
        data:{command:command}, // 自定义命令中可能包含中文
        success : function(data) {
            if (data == "ok") {
                alert("发送成功!");
            }
            else{
                alert("发送失败!");
            }
        }
    });
}
                
// onChange事件
// 自定义每页显示多少条数据
$(document).ready(function() {
    $('#myPageSize').change(function() {
        var size = $("#myPageSize").find('option:selected').val();// 得到下拉菜单的选中项的值
        jQuery("#pageNumber").val(1);
        jQuery("#pageSize").val(size);
        jQuery("#mainForm").submit();
    });
});
 
获得radio的值
var smsType = jQuery("input:[name=sms_type]:radio:checked").val(); // 短信类型

你可能感兴趣的:(JQuery常用标签)