html 代码
- <!doctype html>
- <html lang="zn-CN">
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
- <title></title>
- <style type="text/CSS">
- #login {
- height: 100px;
- width: 100px;
- border: 1px solid black;
- position: relative;
- top:230px;
- left: 750px;
- background: red;
- cursor:pointer;
- }
- </style>
- </head>
- <body>
- <div id="login"></div>
- <script type="text/javascript">
- var oDiv = document.getElementById("login");
- oDiv.onmousedown = function(e){
- var e = e || window.event;
- //e.clientX 鼠标点击时的一点相当于当前窗口左边界的水平坐标.
- //offsetLeft 返回当前元素的左边界到它的包含元素 (body) 的左边界的偏移量, 以像素为单位
- var diffX = e.clientX - oDiv.offsetLeft;// 鼠标指针到 odiv 左边界的像素值(偏移量)
- var diffY = e.clientY - oDiv.offsetTop;
- document.onmousemove = function(e){
- var e = e||window.event;
- oDiv.style.left = e.clientX - diffX + 'px';
- oDiv.style.top = e.clientY -diffY + 'px';
- };
- document.onmouseup = function(){
- document.onmousemove = null;
- document.onmouseup = null;
- }
- }
- </script>
- </body>
- </html>
去掉所有的 html 标签
- <html><head></head>
- <body>
- <script>
- function delHtmlTag(str){
- return str.replace(/<[^>]+>/g,"");// 去掉所有的 html 标记
- }
- var str = "<span style='display:none;'>This is test </span><img src=''>ss</img><strong>haha</strong><br/>";
- str = delHtmlTag(str);
- document.write(str)
- </script>
- </body>
- </html>
来源: http://www.qdfuns.com/article/27225/b235958816d05f2111e453c18a2c2fac.html