• js随笔,css和js禁止网页选择文本,table的class样式使得td的class样式失效,jquery获得元素坐标


    css使用user-select,user-select不是W3C标准,浏览器支持不完整;user-select有两个值,none用户不可以选择文本,text用户可以选择文本

    body{
    -moz-user-select: none; /*火狐*/
    -webkit-user-select: none; /*webkit浏览器*/
    -ms-user-select: none; /*IE10*/
    -khtml-user-select: none; /*早期浏览器*/
    user-select: none;
    }

    也可以使用js控制

    document.body.onselectstart = document.body.ondrag = function(){
    return false;
    }

    对于table中含有class影响了td中的class,使其不起作用,如:

    .pTable td{
    background-color: red;
    }
    .pTd{
    background-color: blue;
    }

    <table class="pTable">
    <tr>
    <td class="pTd">asdfs</td>
    </tr>
    </table>

    这种情况下.pTd就不起作用,需要为其加上!important
    .pTd{
    background-color: blue !important
    ;
    }

    jquery获得元素坐标

    一、获得坐标 

    1.offset() 

    offset() 方法返回或设置匹配元素相对于文档的偏移(位置)。(即视口坐标) 

    该方法返回的对象包含两个整型属性:top 和 left,以像素计。 

    此方法只对可见元素有效。 

    2.position() 

    position() 方法返回匹配元素相对于父元素的位置(偏移)。(相对于父元素的文档坐标) 

    该方法返回的对象包含两个整型属性:top 和 left,以像素计。 

    此方法只对可见元素有效。 

    3.offsetParent() 

    offsetParent() 方法返回最近的祖先定位元素。 

    定位元素指的是元素的 CSS position 属性被设置为 relative、absolute 或 fixed 的元素。 

    可以通过 jQuery 设置 position,或者通过 CSS 的 position 属性。 

    二、获得尺寸 

    1.width() 和 height() 方法 

    width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。 

    height() 方法设置或返回元素的高度(不包括内边距、边框或外边距)。 

    2.innerWidth() 和 innerHeight() 方法 

    innerWidth() 方法返回元素的宽度(包括内边距)。 

    innerHeight() 方法返回元素的高度(包括内边距)。 

    3.outerWidth() 和 outerHeight() 方法 

    outerWidth() 方法返回元素的宽度(包括内边距和边框)。 

    outerHeight() 方法返回元素的高度(包括内边距和边框)。 

    outerWidth(true) 方法返回元素的宽度(包括内边距、边框和外边距)。 

    outerHeight(true) 方法返回元素的高度(包括内边距、边框和外边距)。

  • 相关阅读:
    代码审计中的XSS反射型漏洞
    PHP 代码审计代码执行注入
    4.代码审计之代码注入
    3.代码审计之 命令注入
    2.代码审计之超全局变量
    spring, spring mvc, mybatis整合文件配置详解
    StringUtils方法
    主键与外键
    MySQL面试题
    spring面试题
  • 原文地址:https://www.cnblogs.com/hujiapeng/p/5432286.html
Copyright © 2020-2023  润新知