会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132499个问题
大数据全系列/第十五阶段:Scala分布式语言/Scala的字符串和集合 28351楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 28357楼
WEB前端全系列/第十三阶段:微信小程序-安心食疗(旧)/安心食疗-项目基础配置 28358楼
WEB前端全系列/第十四阶段:React知识体系/React基础知识 28360楼
WEB前端全系列/第十阶段:HTML5游戏方向(旧)/Canvas基础与游戏开发基础 28362楼

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>jq中添加其他监听事件的方法</title>
  <script  src="js/jquery-1.12.3.min.js"></script>
  <style>
    div{
      width: 100px;
      height: 100px;
      border: 1px solid;margin-top: 10px}
  </style>
</head>
<body>
<div  class="div1"></div>
<div  class="div2"></div>
<script>
  /*
   jq中添加其他监听事件的方法
   (2)bind()方法(每个事件之间用空格隔开)
      a.给jq对象一次性添加多个事件监听,并且让多个事件共用一个回调函数
        语法:jq对象.bind('事件1  事件2...',回调函数);

        例子:
       var $div1=  $('.div1');
       var $div2=  $('.div2');
       var num=0;
       $div2.html(num);
       $div1.bind('mouseenter  mouseleave',function(){
       num++;
       $div2.html(num);//鼠标进入和移出div1时div2中的num加1 ;使用jq中自己的方法html 不是js中的innerhtml
       })
      b.bind还可以采用JSON形式的参数来给jq对象添加事件监听。
      说明:给jq对象一次性添加多个事件,并各自拥有不同的回调函数。
      语法:jq对象.bind(JSON参数格式);
      例子:
   var $div1=  $('.div1');
   $div1.bind({
   click:function(){console.log('单击事件');},
   dblclick:function(){console.log('双击事件');},
   mouseenter:function(){console.log('鼠标进入事件');},
   mouseleave:function(){console.log('鼠标离开事件');},
   })
   (3)one方法
   描述:通过one方法添加的事件监听是'一次性的',只能执行一次。
   语法:jq对象.one('事件名',回调函数);
   */
/*  var $div1=  $('.div1');
  $div1.one('click',function(){
    console.log('单击事件');
  })*/
  var $div1=  $('.div1');
  $div1.bind({
    "click":function(){console.log('单击事件');},
    dblclick:function(){console.log('双击事件');},
    mouseenter:function(){console.log('鼠标进入事件');},
    mouseleave:function(){console.log('鼠标离开事件');},
  })
</script>
</body>
</html>

老师,您好

 例子:
   var $div1=  $('.div1');
   $div1.bind({
   click:function(){console.log('单击事件');},
   dblclick:function(){console.log('双击事件');},
   mouseenter:function(){console.log('鼠标进入事件');},
   mouseleave:function(){console.log('鼠标离开事件');},
   })

老师这里采用的JSON格式的参数,为什么不需要像css的JSON格式一样每一个键和值都加上上双引号呢

WEB前端全系列/第三阶段:jQuery编程模块/jQuery基础知识(旧) 28363楼

用IDEA写xml和schema,将schema导入xml的时候 输入xsi报错

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="books"> <!--根元素是books-->
        <xs:complexType>   <!--books中包含了其他的子元素,所以books是复杂的数据类型-->
            <xs:sequence>  <!--按顺序编写-->
                <xs:element name="book" maxOccurs="unbounded">  <!--book可以出现多个,所以maxOccurs="unbounded",不绑定-->
                    <xs:complexType>  <!--book中有也包含其他子元素,所以book是复杂的-->
                        <xs:sequence> <!--按顺序写-->
                            <xs:element name="name" type="xs:string"></xs:element>
                            <xs:element name="author" type="xs:string"></xs:element>
                            <xs:element name="price" type="xs:double"></xs:element>
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:positiveInteger" use="required"></xs:attribute>  <!--book的属性,必须写,所以use="required"-->
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xs="http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation="books.xsd">
    <book id="1001">
        <name>java实战开发</name>
        <author>张小三</author>
        <price>98.5</price>
    </book>

</books>

image.png


JAVA 全系列/第二阶段:JAVA 基础深化和提高/XML 技术(旧) 28365楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637