2024-08-07



// 获取当前页面的URL
var url = $(location).attr('href');
 
// 获取URL中的特定参数值
function getUrlParam(paramName) {
    var reParam = new RegExp('(?:^|&)' + paramName + '=([^&]*)(?:&|$)', 'i');
    var a = window.location.search.substr(1).match(reParam);
    return a ? decodeURIComponent(a[1]) : null;
}
 
// 示例:获取URL参数"id"的值
var id = getUrlParam('id');

这段代码首先使用jQuery获取当前页面的完整URL。然后定义了一个getUrlParam函数,该函数使用正则表达式来查找URL中的特定参数值。最后,通过调用getUrlParam函数并传入参数名,可以获取该参数的值。

2024-08-07

以下是一个简化版的连连看小游戏实现,仅包含核心功能:




<!DOCTYPE html>
<html>
<head>
    <title>连连看游戏</title>
    <style>
        .card {
            width: 80px;
            height: 120px;
            float: left;
            margin: 10px;
            cursor: pointer;
            position: relative;
            background-size: cover;
        }
        .card.matched {
            opacity: 0.5;
        }
    </style>
</head>
<body>
 
<div id="game-board">
    <!-- 卡片动态生成 -->
</div>
 
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
    var cards = ["1.jpg", "2.jpg", "3.jpg", ...]; // 所有卡片图片列表
    var currentCard = null;
    var matchedCards = [];
 
    function shuffle(array) {
        var currentIndex = array.length, temporaryValue, randomIndex;
        while (0 !== currentIndex) {
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
        }
        return array;
    }
 
    function createCardsHTML() {
        var html = '';
        cards = shuffle(cards); // 洗牌
        cards.forEach(function(card) {
            html += '<div class="card" style="background-image: url(' + card + ');"></div>';
        });
        $('#game-board').html(html);
    }
 
    function resetGame() {
        matchedCards = [];
        currentCard = null;
        $('.card').removeClass('matched');
    }
 
    createCardsHTML(); // 创建卡片HTML
 
    $('.card').click(function() {
        var $this = $(this);
        if ($this.hasClass('matched')) return; // 已匹配的卡片不再响应点击
 
        if (currentCard && $this[0] !== currentCard[0]) {
            var card1 = currentCard.attr('style').match(/url<span class="katex">\((.*)\)</span>/)[1];
            var card2 = $this.attr('style').match(/url<span class="katex">\((.*)\)</span>/)[1];
            if (card1 === card2) { // 匹配卡片逻辑
                currentCard.addClass('matched');
                $this.addClass('matched');
                matchedCards.push(currentCard);
                matchedCards.push($this);
                if (matchedCards.length === cards.length / 2) {
                    alert('恭喜你,游戏胜利!');
                    resetGame();
                }
            } else {
                // 不匹配时的处理逻辑(例如:卡片翻转回原样)
                setTimeout(function() {
         
2024-08-07

在jQuery中,我们可以创建一些工具方法来帮助我们处理常见的任务。以下是一些常见的jQuery工具方法:

  1. 事件绑定/解绑:



// 事件绑定
$(selector).on(event, eventHandler);
 
// 事件解绑
$(selector).off(event, eventHandler);
  1. 属性操作:



// 获取属性值
$(selector).attr(attributeName);
 
// 设置属性值
$(selector).attr(attributeName, value);
 
// 移除属性
$(selector).removeAttr(attributeName);
  1. 样式操作:



// 获取样式值
$(selector).css(propertyName);
 
// 设置样式值
$(selector).css(propertyName, value);
  1. 数据绑定:



// 获取数据
$(selector).data(key);
 
// 设置数据
$(selector).data(key, value);
  1. 动画效果:



// 显示元素
$(selector).show(speed, callback);
 
// 隐藏元素
$(selector).hide(speed, callback);
 
// 切换显示和隐藏
$(selector).toggle(speed, callback);
  1. 元素操作:



// 创建元素
$('<element>').text(text).appendTo(selector);
 
// 删除元素
$(selector).remove();
 
// 清空元素内容
$(selector).empty();
  1. AJAX请求:



// 发送GET请求
$.get(url, data, callback);
 
// 发送POST请求
$.post(url, data, callback);
 
// 发送AJAX请求
$.ajax({
    url: url,
    type: type,
    data: data,
    success: function(response) {
        // 请求成功后的回调函数
    },
    error: function(xhr, status, error) {
        // 请求失败后的回调函数
    }
});
  1. 遍历:



// 遍历jQuery对象集合
$(selector).each(function(index, element) {
    // 对每个元素执行的操作
});
  1. 检查是否有选中元素:



// 检查是否有选中元素
if ($(selector).length > 0) {
    // 有选中元素的操作
}
  1. 获取窗口和文档大小:



// 获取窗口宽度
$(window).width();
 
// 获取窗口高度
$(window).height();
 
// 获取文档宽度
$(document).width();
 
// 获取文档高度
$(document).height();

这些方法是jQuery中常用的工具方法,可以帮助我们更加高效地进行Web开发。在实际开发中,我们还可以根据需要创建自定义的工具方法。

2024-08-07

要使用jQuery创建一个简单的文件夹菜单,你可以使用以下代码作为起点。这个例子假设你已经在你的页面中包含了jQuery库。

HTML:




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Folder Menu</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
 
<ul id="folderMenu">
  <li data-folder="Photos">Photos
    <ul>
      <li data-file="photo1.jpg">photo1.jpg</li>
      <li data-file="photo2.jpg">photo2.jpg</li>
      <li data-file="photo3.jpg">photo3.jpg</li>
    </ul>
  </li>
  <li data-folder="Documents">Documents
    <ul>
      <li data-file="doc1.pdf">doc1.pdf</li>
      <li data-file="doc2.pdf">doc2.pdf</li>
    </ul>
  </li>
</ul>
 
<script src="script.js"></script>
</body>
</html>

CSS (style.css):




#folderMenu {
  list-style-type: none;
  padding: 0;
}
 
#folderMenu > li {
  cursor: pointer;
}
 
#folderMenu li ul {
  display: none;
}

jQuery (script.js):




$(document).ready(function() {
  $('#folderMenu > li').on('click', function() {
    var $this = $(this);
    if ($this.children('ul').length) {
      $this.children('ul').toggle();
    }
  });
});

这个例子中,当你点击一个文件夹时,它下面的子文件夹或文件会被显示或隐藏。你可以根据需要添加更多的文件夹和文件,或者添加删除、重命名等功能。

2024-08-07

使用jQuery实现一个简单的倒计时可以通过定时器函数setInterval来实现。以下是一个实现倒计时的示例代码:

HTML部分:




<div id="timer">00:05</div>

CSS部分(可选,用于更好的视觉效果):




#timer {
  font-size: 24px;
  font-weight: bold;
}

jQuery部分:




$(document).ready(function(){
  var countdownDuration = 5; // 倒计时时间,以秒为单位
  var display = $('#timer');
 
  var timer = setInterval(function() {
    var minutes = parseInt(countdownDuration / 60, 10);
    var seconds = parseInt(countdownDuration % 60, 10);
 
    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
 
    display.text(minutes + ":" + seconds);
 
    if (--countdownDuration < 0) {
      clearInterval(timer);
      display.text("时间到!");
    }
  }, 1000);
});

在这段代码中,countdownDuration 变量用于设置倒计时的时间,单位是秒。display 变量指向页面中倒计时显示的元素。timer 是计时器的ID,用于在倒计时结束后停止计时器。每隔1秒(1000毫秒)更新一次显示时间,时间到了0秒则清除计时器并显示"时间到!"。

2024-08-07

在Vue项目中引入ECharts 3D路径图(Flights GL),首先需要安装必要的库:echartsecharts-gljquery。以下是安装命令:




npm install echarts --save
npm install echarts-gl --save
npm install jquery --save

然后,在Vue组件中引入这些库并初始化ECharts图表:




<template>
  <div ref="chart" style="width: 600px; height: 400px;"></div>
</template>
 
<script>
import * as echarts from 'echarts/core';
import {
  GridComponent,
  TooltipComponent,
  TitleComponent
} from 'echarts/components';
import { CanvasRenderer } from 'echarts/renderers';
import 'echarts-gl';
import $ from 'jquery';
 
import { pathSimplifier } from 'echarts-gl/components';
import {
  geo,
  lines3D,
  scatter3D,
  grid3D,
  timeline
} from 'echarts-gl/charts';
 
echarts.use([
  pathSimplifier,
  lines3D,
  scatter3D,
  grid3D,
  timeline,
  geo,
  TitleComponent,
  TooltipComponent,
  GridComponent,
  CanvasRenderer
]);
 
export default {
  mounted() {
    const chart = echarts.init(this.$refs.chart);
    const option = {
      // ECharts 3D路径图的配置项
    };
    chart.setOption(option);
  }
};
</script>

请注意,这只是一个基本的示例,您需要根据您的具体需求配置ECharts 3D路径图的具体选项。

2024-08-07



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>FancyBox 图片预览</title>
    <link rel="stylesheet" href="path/to/jquery.fancybox.css" />
    <script src="path/to/jquery.min.js"></script>
    <script src="path/to/jquery.fancybox.min.js"></script>
</head>
<body>
 
<a data-fancybox="gallery" href="big_image_1.jpg"><img src="thumb_image_1.jpg" width="100" height="100"></a>
<a data-fancybox="gallery" href="big_image_2.jpg"><img src="thumb_image_2.jpg" width="100" height="100"></a>
<a data-fancybox="gallery" href="big_image_3.jpg"><img src="thumb_image_3.jpg" width="100" height="100"></a>
 
<script>
    $(document).ready(function() {
        $("[data-fancybox]").fancybox();
    });
</script>
 
</body>
</html>

在这个例子中,我们首先引入了必要的CSS和JavaScript文件。然后,我们创建了三个图片预览链接,每个链接包含一个缩略图和对应的大图。我们使用data-fancybox属性来指定预览组的名字。最后,在文档加载完成后,我们使用jQuery初始化了FancyBox。

2024-08-07

JQuery是一个快速、简洁的JavaScript库,设计的目标是“写得少,做得多”。它不仅简化了JavaScript编程,还能增强用户与网站的交互,并促进跨浏览器兼容性的开发。

  1. 引入JQuery库

在HTML文件中,我们需要通过<script>标签引入JQuery库。




<!DOCTYPE html>
<html>
<head>
    <title>JQuery 示例</title>
    <!-- 引入JQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <h1>Hello, jQuery!</h1>
</body>
</html>
  1. JQuery选择器

JQuery选择器允许我们选择DOM元素进行操作。




<!DOCTYPE html>
<html>
<head>
    <title>JQuery 示例</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                $("p").hide();
            });
        });
    </script>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph.</p>
    <button>Click me</button>
</body>
</html>

在上述示例中,当按钮被点击时,段落会被隐藏。

  1. JQuery事件

JQuery允许我们绑定各种事件处理程序。




<!DOCTYPE html>
<html>
<head>
    <title>JQuery 示例</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("#myBtn").click(function(){
                $("p").slideToggle();
            });
        });
    </script>
</head>
<body>
    <p>这是一个段落。</p>
    <button id="myBtn">点击我</button>
</body>
</html>

在上述示例中,当按钮被点击时,段落将滑入或滑出。

  1. JQuery效果

JQuery提供了一系列的效果,如淡入淡出、滑入滑出等。




<!DOCTYPE html>
<html>
<head>
    <title>JQuery 示例</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                $("p").fadeToggle();
            });
        });
    </script>
</head>
<body>
    <p>这是一个段落。</p>
    <button>点击我</button>
</body>
</html>

在上述示例中,当按钮被点击时,段落将淡入或淡出。

2024-08-07

jQuery是一种快速、简洁的JavaScript库,它使得HTML文档的遍历和操作、事件处理、动画和Ajax交互等变得更加简单,并且方便了JavaScript和Ajax的使用。

以下是一些常用的jQuery方法和代码示例:

  1. 选择器:



$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});
  1. 事件:



$(document).ready(function(){
  $("#myButton").click(function(){
    alert("按钮被点击了!");
  });
});
  1. CSS操作:



$(document).ready(function(){
  $("p").css("background-color", "yellow");
});
  1. HTML操作:



$(document).ready(function(){
  $("#myDiv").html("<p>这是新添加的段落。</p>");
});
  1. 属性操作:



$(document).ready(function(){
  $("img").attr("width", "300");
});
  1. 添加和删除类:



$(document).ready(function(){
  $("p").addClass("myClass");
  $("p").removeClass("myClass");
});
  1. 动画:



$(document).ready(function(){
  $("div").fadeIn();
  $("div").fadeOut();
});
  1. AJAX请求:



$(document).ready(function(){
  $.ajax({
    url: "test.html",
    success: function(result){
      $("#div1").html(result);
    }
  });
});
  1. 创建和添加元素:



$(document).ready(function(){
  $("body").append("<p>这是新添加的段落。</p>");
});
  1. 使用jQuery each()方法遍历数组:



$(document).ready(function(){
  $.each([52, 97], function(index, value){
    alert("Index " + index + ": " + value);
  });
});

以上是jQuery的一些基本用法,实际上jQuery提供了更多强大的功能,如Promise、Deferred对象、动画等。

2024-08-07

要使用jQuery实现一个Cron表达式选择器,你需要创建一个用户界面来允许用户配置Cron表达式的各个字段,并使用jQuery来处理用户的交互。以下是一个简单的Cron表达式选择器的实现示例:

HTML 部分:




<div id="cron-selector">
  <label for="second">秒:</label>
  <select id="second">
    <!-- 填充秒数选项 -->
  </select>
  
  <label for="minute">分钟:</label>
  <select id="minute">
    <!-- 填充分钟数选项 -->
  </select>
  
  <label for="hour">小时:</label>
  <select id="hour">
    <!-- 填充小时数选项 -->
  </select>
  
  <label for="day-of-month">日:</label>
  <select id="day-of-month">
    <!-- 填充日期选项 -->
  </select>
  
  <label for="month">月:</label>
  <select id="month">
    <!-- 填充月份选项 -->
  </select>
  
  <label for="day-of-week">星期:</label>
  <select id="day-of-week">
    <!-- 填充星期数选项 -->
  </select>
  
  <button id="generate-cron">生成Cron表达式</button>
  
  <div id="cron-expression">Cron表达式: 0 0 0 ? * *</div>
</div>

jQuery 部分:




$(document).ready(function() {
  // 初始化选项
  for (var i = 0; i < 60; i++) {
    $('#second, #minute').append($('<option></option>').val(i).html(i < 10 ? '0' + i : i));
  }
  for (var i = 0; i < 24; i++) {
    $('#hour').append($('<option></option>').val(i).html(i < 10 ? '0' + i : i));
  }
  for (var i = 1; i <= 31; i++) {
    $('#day-of-month').append($('<option></option>').val(i).html(i < 10 ? '0' + i : i));
  }
  for (var i = 1; i <= 12; i++) {
    $('#month').append($('<option></option>').val(i).html(i));
  }
  for (var i = 0; i < 7; i++) {
    $('#day-of-week').append($('<option></option>').val(i).html(i));
  }
 
  $('#generate-cron').click(function() {
    var second = $('#second').val();
    var minute = $('#minute').val();
    var hour = $('#hour').val();
    var dayOfMonth = $('#day-of-month').val();
    var month = $('#month').val();
    var dayOfWeek = $('#day-of-week').val();
 
    var cronExpression = [second, minute, hour, dayOfMonth, month, dayOfWeek].join(' ');
    $('#cron-expression').text('Cron表达式: ' + cronExpression);
  });
});

这个实现提供了基本的Cron表达式字段选择,并允许用户选择每个字段的值。点击“生成Cron表达式”按钮后,将根据用户的选择生成并显示Cron表达式。这个实现没有处理特定的Cron语法规则,比如允许用户输入一个范围或列表的值,也没有进行错误处理,比如确保月份的日期不会超出范围。在实际应用中,你可能需要添加更多的功能和验证来完善这个Cron表达式选