$(function() { $(‘#send‘).click(function() { $.ajax({ type: "GET", //GET或POST, async:true, //默认设置为true,所有请求均为异步请求。 url: "http://www.idaima.com/xxxxx.php", data: { username: $("#username").val(), content: $("#content").val() }, dataType: "json", //xml、html、script、jsonp、text beforeSend:function(){}, complete:function(){}, success: function(data) { alert(data) }, error:function(){}, }); }); });
$("input[type=‘checkbox‘]").is(‘:checked‘) //返回结果:选中=true,未选中=false
var chk_value =[]; $(‘input[name="test"]:checked‘).each(function(){ chk_value.push($(this).val()); });
$("document").ready(function() { $("#btn1").click(function() { $("[name=‘checkbox‘]").attr("checked", ‘true‘); //全选 }) $("#btn2").click(function() { $("[name=‘checkbox‘]").removeAttr("checked"); //取消全选 }) $("#btn3").click(function() { $("[name=‘checkbox‘]:even").attr("checked", ‘true‘); //选中所有奇数 }) $("#btn4").click(function() { $("[name=‘checkbox‘]").each(function() { //反选 if ($(this).attr("checked")) { $(this).removeAttr("checked"); } else { $(this).attr("checked", ‘true‘); } }) }) })
$("#select").val()
$(‘input:radio:checked‘).val(); $("input[type=‘radio‘]:checked").val(); $("input[name=‘rd‘]:checked").val();
$(‘input:radio:first‘).attr(‘checked‘, ‘checked‘);
$(‘input:radio:first‘).attr(‘checked‘, ‘true‘);
$(‘input:radio:last‘).attr(‘checked‘, ‘checked‘);
$(‘input:radio:last‘).attr(‘checked‘, ‘true‘);
$("input:radio[value=‘rd2‘]").attr(‘checked‘,‘true‘);
$("input[value=‘rd2‘]").attr(‘checked‘,‘true‘);
$("#msg").css("background"); //返回元素的背景颜色 $("#msg").css("background","#ccc") //设定元素背景为灰色 $("#msg").height(300); $("#msg").width("200"); //设定宽高 $("#msg").css({ color: "red", background: "blue" });//以名值对的形式设定样式 $("#msg").addClass("select"); //为元素增加名称为select的class $("#msg").removeClass("select"); //删除元素名称为select的class $("#msg").toggleClass("select"); //如果存在(不存在)就删除(添加)名称为select的class
$(document).keyup(function(event){ if(event.keyCode ==13){ $("#submit").trigger("click"); } });
原文:https://www.cnblogs.com/daimaxuejia/p/10942664.html