作为一个.net后台开发的程序猿,博客里既然大多都是前端相关的博文。是不是该考虑换方向了,转前端开发得了 ... 小小吐槽一下,近期受该不该跳槽所困惑,我有选择困难症! 继续前端,这次说一下输入框 placeholder 这个属性。 html5 的新属性,就是在输入框没输入值的时候,显示的提示文字(自己的理解),例如:貌似很好用,但也只能在支持 html 的浏览器版本中显示,而对于不能支持的浏览器版本,让我这种极力追求完美的开发者来...
element.clientWidth //元素的实际宽度,不算边框 element.clientHeight //元素的实际高度,不算边框 element.offsetWidth //元素的实际宽度,加上边框 element.offsetHeight //元素的实际高度,加上边框 element.scrollWidth //这个说法很多,我测试下来应该是元素实际宽度-滚动条的宽度 element.scrollHeight //这个说法很多,我测试下来应该是元素实际高度-滚动条的高度 element.offsetLeft //相对于父对象...
本人是一名小白,应届毕业生,以前没用过jquery,最近做项目用到了jquery。在做的过程中走了很多弯路,不停的搜索。总结出了一些用法,供大家参考: 最基本的选择器语法包括:id、class、标签、属性,这和css选择器是一致的。 ID选择器要在ID前加#,比如要选择一个ID为myDivID的div元素()可以这样写: 代码如下: $("#myDivID"); D是不能重复的,所以ID选择器选出来的是一个jquery对象。 class选择器要在class前加点(.),比如要...
1、对于没有中划线的css属性一般直接使用style.属性名即可。 如:obj.style.margin,obj.style.width,obj.style.left,obj.style.position等。 2、对于含有中划线的css属性,将每个中划线去掉并将每个中划线后的第一个字符换成大写即可。 如:obj.style.marginTop,obj.style.borderLeftWidth,obj.style.zIndex,obj.style.fontFamily等。 因为float是Javascript的保留字,那怎么在js中书写样式表中的float呢? 我们不能直接使用...
document.title //设置文档标题等价于HTML的title标签 document.bgColor //设置页面背景色 document.fgColor //设置前景色(文本颜色) document.linkColor //未点击过的链接颜色 document.alinkColor //激活链接(焦点在此链接上)的颜色 document.vlinkColor //已点击过的链接颜色 document.URL //设置URL属性从而在同一窗口打开另一网页 document.fileCreatedDate //文件建立日期,只读属性 document.fileModifiedDate //文件修改日...
altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y 1.altKey 描述: 检查alt键的状态。 语法: event.altKey 可能的值: 当alt键按下时,值为 TRUE ,否则为 FALSE 。只读。 2.button 描述: 检查按下的鼠标键。 语法: event.button 可能的值: 0 没按键 1 按左键 2 按右...
一些简单的例子,用原生js和jQuery实现随意改变div属性,和重置。代码如下: 代码如下: 函数传参,改变Div任意属性的值 body,p{margin:0;padding:0;} body{color:#333;font:12px/1.5 Tahoma;padding-top:10px;} #outer{width:300px;margin:0 auto;} p{margin-bottom:10px;} button{margin-right:5px;} label{width:5em;display:inline-block;text-align:right;} input{padding:3px;font-family:inherit;border:1px solid #cc...
代码如下: var fontSize = $(this).attr(style,function(i,s){ return s.replace(/font-size:\s*(\d+.{0,1}\d*)/, function(a){ return a + px; }); }); //console.debug("font-size: "+ $(this).attr(style).match(/(?:font-size:)s*(\d+.{0,1}\d*)/)); var style = $(this).attr(style); var fontSize = $(this).css(font-size,function(){ var s = style.match(/(?:font-size:)s*(\d+.{0,1}\d*)/)[0].replace(/font-size:/,); r...
1.创建div元素: Javascript代码 代码如下: <scripttypescripttype="text/javascript"> functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.innerHTML="Testcreateadivelement!"; document.body.appendChild(createDiv); } </ script> <scripttypescripttype="text/javascript"> functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.innerHTML="Testcreateadivelemen...
之前没有注意过div的background-image这个属性,只是设置它的url,今天遇到一个问题特此做一下记录。 代码如下: 在js中想获取image属性 代码如下: document.getElementById(img_2).style.backgroundImage; 注意黑体部分哦,div中的是background-image,而获取属性时是backgroundImage。应该是所有这种带有“-”的style都要这么做吧,这个有待验证, 先记录此问题学习。
先上需要用到的全部代码片段(截取) 代码如下: MenuControl.prototype.boxDisplay = false;//是否显示图层选择菜单 MenuControl.prototype.controlUI; MenuControl.prototype.show = function(){ if(pointControl.boxDisplay){ pointControl.hide(); } menuBoxDiv.style.display = ""; this.boxDisplay = true; this.controlUI.style.backgroundColor = #DDDDDD; }; MenuControl.prototype.hide = function(){ menuBoxDiv.style....
在本文中用JQuery对class属性的操作方法实现页面中的按钮开关效果。 首先定义两个class: 代码如下: .controlOff{ display:inline-block; width:130px; height:36px; cursor:pointer; background-image:url("../iclass/images/teach_off.png"); background-repeat: no-repeat; } .controlOn{ display:inline-block; width:130px; height:36px; cursor:pointer; background-image:url("../iclass/images/teach_on.png"); backgroun...
js修改input的type属性有些限制。当input元素还未插入文档流之前,是可以修改它的值的,在ie和ff下都没问题。但如果input已经存在于页面,其type属性在ie下就成了只读属性了,不可以修改。在ff下仍是可读写属性。 今天遇到个问题,输入框有默认值“密码”,但获得焦点时,“密码”两字会去掉,输入时直接变成”****“的password类型。很明显,一开始的时候,input的类型是text,后来变成了password类型。直观的思路是用js修改input...
一个针对jQuery属性选择器的小例子,增加对jQUery属性选择器的理解: 代码如下: a{ margin-right:20px; } ol{ position:relative; width:600px; margin-left:400px; } dt{ margin:10px; height:100px; background-color:#EAEAEA; border:3px dotted orange; } .showMessage{ width:380px; float:left; background-color:#D8D8D8; border:1px dotted red; } $(document).ready(function(){ var subject = ""; var describe =...
代码如下: //jquery 通过得到对象的长度判断对象是否存在 function testJquery() { if ($(".tel").length > 0) { alert("存在"); } else { alert("不存在"); } }