Jquery学习前传

news/2024/7/11 0:14:48 标签: jquery, 前传

博客核心内容:

      • 加载顺序
      • 如何选择标签并进行执行
      • 通过Jquery如何获取某个标签中某个属性对应的数值方法1
      • 通过Jquery如何获取某个标签中某个属性对应的数值方法2
      • 通过Jquery如何获取某个标签中某个属性对应的数值方法3
      • 常见的创建标签
      • 通过浏览器查找标签的技巧注意浏览器中就不要加var了
      • JS和Jquery当中一种值得学习的函数加载方式
    • Form表单中通过a标签向后台发送数据
    • Jquery中如何通过attr设置某个属性的数值重要强烈推荐

加载顺序:

这里写图片描述

如何选择标签并进行执行

这里写图片描述

jquery如何获取某个标签中某个属性对应的数值方法1">通过Jquery如何获取某个标签中某个属性对应的数值方法1

例如:我们想给下面的a标签添加事件并获取a标签中news_id=”{{ news.id }}”中news_id这个属性对应的数值。

<div>
     <div>{{ news.title }}</div>
     <div> 发布者:{{ news.publisher.username }} - 评论个数:{{ news.comment_count }} - 
     <a class="news-like" href="#" news_id="{{ news.id }}">赞:{{ news.favor_count }}</a></div>
     <br>
</div>

方法:很重要

function bindFavorEvent() {
        $('.news-like').click(function(){
            {#获取当前新闻的ID并进行输出#}
             alert($(this).attr('news_id'))
        })
    }

效果示例:
这里写图片描述

jquery如何获取某个标签中某个属性对应的数值方法2">通过Jquery如何获取某个标签中某个属性对应的数值方法2

对于另外一种用法,我也试了,用着也可以。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通过定时器实现文本框的数值1分钟变一次</title>
</head>
<body>
    <input style="border-radius: 10%" type="text">&nbsp;<button>start</button>&nbsp;<button>end</button>
</body>
<script src="jquery-3.1.1.js"></script>
<script>
    start_button = $('button').eq(0)
    stop_button = $('button').eq(1)
    input_button = $('input').eq(0)

    start_button.click(function () {
        current_time = new Date().toString()
        input_button.val(current_time)
        console.log(input_button.val())
    })


</script>
</html>

效果展示:
这里写图片描述

jquery如何获取某个标签中某个属性对应的数值方法3">通过Jquery如何获取某个标签中某个属性对应的数值方法3

if (arg.status){
                          {# 如果点赞成功+1 #}
                           var orign = obj.text();
                           var new_value = parseInt(orign) + 1;
                           obj.text(new_value);
                      }else{
                          {# 如果点赞失败-1#}
                           var orign = obj.text();
                           var new_value = parseInt(orign) - 1;
                           obj.text(new_value);
                      }

这里写图片描述

常见的创建标签

if (tagname != "DIV") {
                        var tag = document.createElement("div")
                        tag.innerText = "用户名或者密码有误"
                        tag.setAttribute("name", "error")
                        tag.classList.add("text-center")
                        tag.style.color = "red"
                        {# 登陆标签后面加入这个新标签#}
                        $("input[value=登录]").after(tag)
                    }

通过浏览器查找标签的技巧(注意:浏览器中就不要加var了)

<iframe src="" name="xxxxx" style="">
       #document
        <html>
           <head></head>
           <body>{"msg": null, "data": "static\\images\\iframe.png", "status": true}</body>
        </html>
    </iframe>

这里写图片描述
看来以后我们通过浏览器这种方式就可以更好的使用jquery了。

jquery当中一种值得学习的函数加载方式">JS和Jquery当中一种值得学习的函数加载方式:

这里写图片描述

Form表单中通过a标签向后台发送数据

这里写图片描述

jquery中如何通过attr设置某个属性的数值重要强烈推荐">Jquery中如何通过attr设置某个属性的数值(重要,强烈推荐)

标签.attr(‘属性值’,’value’)

success:function (arg) {
                {#   模拟长轮询,向后台在次发送请求  #}
                if (arg.code == 408){
                    checkLogin();
                }else if(arg.code == 201){
                    $('#img').attr('src',arg.data)
                }
            }

http://www.niftyadmin.cn/n/1159024.html

相关文章

Django系列7---cookie、session、json、csrf_token

博客核心内容&#xff1a; json相关论坛&#xff1a;http://bbs.csdn.net/topics/300218709 为了避免csrf,我们前端一般这样写&#xff1a; <form action"/upload/" method"POST" enctype"multipart/form-data">{% csrf_token %}<inp…

css常用样式属性详细介绍

对于初学css的来说&#xff0c;肯定会觉得这么多样式不好记&#xff0c;而且记住了也容易忘&#xff0c;其实刚开始我们不用去记这么多的样式&#xff0c;确实是记了也会忘&#xff0c;刚开始只需记住一些常用的就可以了&#xff0c;然后在慢慢的使用过程当中接触并学习一些高级…

Python中常用的模块--Log日志模块

实例代码&#xff1a; #!/usr/bin/python # -*- coding:utf-8 -*-import os import datetime import sys import logging from logging import StreamHandlerclass myLog():def __init__(self,basedirNone,nameNone):# 获取当前目录if basedir:self.basedir basedirelse:self…

通过JS实现轮播图

博客参考&#xff1a; 1、http://blog.csdn.net/a2011480169/article/details/76218022 &#xff08;绝对定位和相对定位&#xff09; 2、轮播图 http://www.jb51.net/article/94598.htm 3、定时器和计时器 http://blog.csdn.net/a2011480169/article/details/76706014 …

smartGWT DataSource数据动态加载

昨天和今天早上&#xff0c;用DataSource从数据库后台动态加载数据&#xff0c;我的业务是这样的&#xff1a; 我有两个SelectItem选择框&#xff0c;第一个选择框里面的数据是单位&#xff0c;第二个选择框中的数据是对应单位的人&#xff0c;因为人可能有重名&#xff0c;所以…

HTTP请求中的form data和request payload的区别等(转载)

阅读博文之后的小总结&#xff1a; 题目&#xff1a;HTTP请求中的form data和request payload的区别 在Chrome中调试发现&#xff0c;.ajax发送的请求显示在requestpayload下面&#xff0c;而使用.post方法发送的请求显示在form data下面。也就是说payload中的数据是前台通过…

01-02 Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS)

The primary role of the CLR is to locate, load, and manage .NET objects on your behalf. CLR主要的角色就是为你定位&#xff0c;加载和管理.Net对象。 The CLR also takes care of a number of low-level details such as memory management, application hosting, coor…

Python获取并输出当前日期时间

转载网址&#xff1a;http://www.cnblogs.com/kerwinC/p/5760811.html