当前位置: 首页 > news >正文

【Django】 js实现动态赋值、显示show隐藏hide效果

文章目录

  • 需要达到的前端效果预览:
  • 实现步骤
    • 复制bootstrp代码(buttons)
    • 复制bootstrp代码(Alert警告框)
    • 写js
    • 测试效果

需要达到的前端效果预览:

{% load static %}
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet"href="{% static "antapp/bootstrap/bootstrap.min.css" %}"><title>Document</title></head><body><div class="row" style="margin-top: 20px;margin-left: 40px;"><button type="button" id="chinese" class="btn btn-primary" style="margin-left: 5px;">语文</button><button type="button" id="math" class="btn btn-warning" style="margin-left: 5px;">数学</button><button type="button" id="english" class="btn btn-success" style="margin-left: 5px;">英语</button><button type="button" id="show" class="btn btn-danger" style="margin-left: 5px;">显示</button><button type="button" id="hide" class="btn btn-secondary" style="margin-left: 5px;">隐藏</button></div><div class="row"  style="margin-top: 20px; margin-left: 40px;"><div id="showtxt" class="alert alert-primary" role="alert"> A simple primary alert—check it out!</div></div><script src="{% static "antapp/bootstrap/jquery.min.js" %}"></script><script src="{% static "antapp/bootstrap/bootstrap.bundle.min.js" %}"></script><script>var btconfig={"chinese":"语文成绩100","math":"数学成绩99","english":"英语成绩98",}$(function(){$("#chinese").click(function(){alert(btconfig["chinese"])$("#showtxt").html(btconfig["chinese"])})$("#math").click(function(){$("#showtxt").html(btconfig["math"])})$("#english").click(function(){$("#showtxt").html(btconfig["english"])})$("#show").click(function(){$("#showtxt").show()})$("#hide").click(function(){$("#showtxt").hide()})})</script></body>
</html>

在这里插入图片描述

实现步骤

复制bootstrp代码(buttons)

<button type="button" id="chinese" class="btn btn-primary" style="margin-left: 5px;">语文</button>
<button type="button" id="math" class="btn btn-warning" style="margin-left: 5px;">数学</button>
<button type="button" id="english" class="btn btn-success" style="margin-left: 5px;">英语</button>
<button type="button" id="show" class="btn btn-danger" style="margin-left: 5px;">显示</button>
<button type="button" id="hide" class="btn btn-secondary" style="margin-left: 5px;">隐藏</button>

在这里插入图片描述
上图使用的工具链接如下:
https://blog.csdn.net/xzzteach/article/details/140732891

复制bootstrp代码(Alert警告框)

https://v4.bootcss.com/docs/components/alerts/

<div id="showtxt" class="alert alert-primary" role="alert"> A simple primary alert—check it out!</div>

在这里插入图片描述

写js

        <script>var btconfig={"chinese":"语文成绩100","math":"数学成绩99","english":"英语成绩98",}$(function(){$("#chinese").click(function(){alert(btconfig["chinese"])$("#showtxt").html(btconfig["chinese"])})$("#math").click(function(){$("#showtxt").html(btconfig["math"])})$("#english").click(function(){$("#showtxt").html(btconfig["english"])})$("#show").click(function(){$("#showtxt").show()})$("#hide").click(function(){$("#showtxt").hide()})})</script>

测试效果

在这里插入图片描述

http://www.lryc.cn/news/408610.html

相关文章:

  • qt--做一个拷贝文件器
  • Eclipse 搭建 C/C++ 开发环境以及eclipse的使用
  • 【初阶数据结构】复杂度算法题篇
  • 20240725项目的maven环境报红-重新配置maven
  • 若依 ruoyi poi Excel合并行的导入
  • 优化算法:1.遗传算法(GA)及Python实现
  • 企业化运维(8)Docker容器技术
  • Unity C#底层原理(二)
  • 计算机网络-配置路由器ACL(访问控制列表)
  • 51单片机嵌入式开发:20、STC89C52R基于C51嵌入式点阵广告屏的设计
  • VLC输出NDI媒体流
  • WiFi 局域网通信 - 发现服务和解析
  • ChatGPT建议前端学习计划
  • YOLO5项目目录最强解析
  • 【python】sklearn基础教程及示例
  • Linux:传输层(2) -- TCP协议(2)
  • AcWing 802. 区间和
  • 实验2-2-1 温度转换
  • Spark实时(六):Output Sinks案例演示
  • 在SQL编程中DROP、DELETE和TRUNCATE的区别
  • 【AI大模型】Prompt 提示词工程使用详解
  • 学习记录day18——数据结构 算法
  • 一篇文章带你学完Java所有的时间与日期类
  • 利用GPT4o Captcha工具和AI技术全面识别验证码
  • 大学生算法高等数学学习平台设计方案 (第一版)
  • 机器学习算法与Python实战 | 两行代码即可应用 40 个机器学习模型--lazypredict 库!
  • 使用WebSocket协议调用群发方法将消息返回客户端页面
  • 【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第三篇 嵌入式Linux驱动开发篇-第五十七章 Linux中断实验
  • 每日一题~961div2A+B+C(阅读题,思维,数学log)
  • Fireflyrk3288 ubuntu18.04添加Qt开发环境、安装mysql-server