jQuery 备忘单对于初学者和有经验的开发人员都是很好的参考
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
$(selector).methodOrFunction();
$('#menu').on('click', () =>{
$(this).hide();
});
$("body").css("background", "red");
$(document).ready(function() {
// 在加载 DOM 后运行
alert('DOM fully loaded!');
});
$(function(){
// 在加载 DOM 后运行
alert('DOM fully loaded!');
});
$("button").click(() => {
$(":button").css("color", "red");
});
$("selector1, selector2 ...selectorn")
$('h2').css({
color: 'blue',
backgroundColor: 'gray',
fontSize: '24px'
});
$('.button').addClass('active');
$('.button').on('mouseleave', evt => {
let e = evt.currentTarget;
$(e).removeClass('active');
});
$('.choice').toggleClass('highlighted');
.css()
方法使用此对象来查看它是否可以将 px 附加到无单位值/*<span>Span.</span>*/
$('span').after('<p>Paragraph.</p>');
/*<span>Span.</span><p>Paragraph.</p>*/
/*<span>Span.</span>*/
$('<span>Span.</span>').replaceAll('p');
/*<p>Span.</p>*/
/*<span>This is span.</span>*/
$('span').wrap('<p></p>');
/*<p><span>This is span.</span></p>*/
// 鼠标事件“点击”
$('#menu-button').on('click', () => {
$('#menu').show();
});
// 键盘事件“键盘”
$('#textbox').on('keyup', () => {
$('#menu').show();
});
// 滚动事件“滚动”
$('#menu-button').on('scroll', () => {
$('#menu').show();
});
$('#menu').on('click', event => {
$(event.currentTarget).hide();
});
$('#menu-btn').on('mouseenter', () => {
$('#menu').show();
}).on('mouseleave', () => {
$('#menu').hide();
});
$( "p" ).click(function( event ) {
event.stopPropagation();
// Do something
});
$('#menu-button').on('click', () => {
// $('#menu').fadeIn(400, 'swing')
$('#menu').fadeIn();
});
$('#menu-button').on('click', () => {
// $('#menu').fadeOut(400, 'swing')
$('#menu').fadeOut();
});
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize()
}).done(function(server_data){
console.log("success" + server_data);
}).fail(function(jqXHR, status, err){
console.log("fail" + err);
});