zoukankan      html  css  js  c++  java
  • jquery框架和mvvm框架的类名操作性对比

    操作元素选取的是img元素

    mvvm选取的是avalon框架

    操作类名上感觉还是jquery有着很强的优势,毕竟有着toggle方法

    mvvm上实现相同效果还得做逻辑判断,比较麻烦,代码行数就多了几行。

    点击看效果demo

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <link href="./demo.css" rel="stylesheet">
        <link href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.css" rel="stylesheet">
        <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
        <script src="https://unpkg.com/avalon2@2.2.8/dist/avalon.js"></script>
        <style>
            .clickClass{
                padding: 5px;
                border: 2px solid #e4e4e4;
                background: #868e96;
            }
        </style>
    </head>
    <body>
        <div class="demo-container">
            <div class="header">
                <i><b>jquery和mvvm的类名操作比较</b></i>
            </div>
            <div class="method-title">jq方法</div>
            <div class="method-container">
               <img id="img1" src=".././images/imgcommon1.jpg">
            </div>
            <div class="method-title">mvvm方法</div>
            <div class="method-container" :controller="img2">
                <img  ms-click="@clickImg" id="img2" :class="@className" src=".././images/imgcommon1.jpg">
            </div>
        </div>
        <script>
    
                //jq way
                $('#img1').click(function(e) {
                    // $(this).addClass('clickClass');
                    $(this).toggleClass('clickClass');
                });
    
                //mvvm way
                let mvvmImg = avalon.define({
                    $id: 'img2',
                    className: '',
                    clickImg(e) {
                        this.className = 'clickClass';
                    }
                });      
        </script>
    </body>
    </html>
    

      

  • 相关阅读:
    Struts2+Spring+Ibatis集成合并
    spring多个定时任务quartz配置
    Quartz作业调度框架
    百度搜索URL参数含义
    代理IP抓取
    解决HttpWebRequest和HtmlAgilityPack采集网页中文乱码问题
    移动端上传头像-相册、拍摄-旋转
    订单倒计时
    css flex布局 实例
    currentTarget与target
  • 原文地址:https://www.cnblogs.com/lemon-zhang/p/8003820.html
Copyright © 2011-2022 走看看