
可以参考下面的代码:
<style>
a{display:block;float:left}
</style>
<div style="border:1px solid #cccccc">
<a id="a1" href="#" class="float_r" style="margin-top:10px;">asd</a>
<a id="a2" href="#" class="float_r" style="margin-top:20px;">asd</a>
<a id="a3" href="#" class="float_r" style="margin-top:30px;">asd</a>
<a id="a4" href="#" class="float_r" style="margin-top:40px;">asd</a>
<a id="a5" href="#" class="float_r" style="margin-top:50px;">asd</a>
</div>
<script>
for(var i=1;i<6;i++){
documentgetElementById('a'+i)stylemarginTop = parseInt(documentgetElementById('a'+i)stylemarginTop)+5+'px';
}
</script>
JavaScript是一种属于网络的脚本语言,已经被广泛用于Web应用开发,常用来为网页添加各式各样的动态功能,为用户提供更流畅美观的浏览效果。
通常JavaScript脚本是通过嵌入在HTML中来实现自身的功能的。它最初由Netscape的Brendan Eich设计。JavaScript是甲骨文公司的注册商标。Ecma国际以JavaScript为基础制定了ECMAScript标准。
扩展资料:
javaScript参考函数
anchor("name")用来把字符串转换为HTML锚面标志内(<A NAME=>)
big() 把字符串中的文本变成大字体(<BIG>)
blink() 把字符串中的文本变成闪耀字体(<BLINK>)
bold() 把字符串中的文本变成乌字体(<B>)
fixed() 把字符串中的文本变成流动间距字体,便电报情势(<TT>)
fontcolor(color)设置字符串中文本的色彩(<FONT COLOR=>)
Fontsize(size) 把字符串中的文本变成指定大小(<FONTSIZE=>)
italics() 把字符串中的白原变成斜字体(<I>)
Link(url)用来把字符串转换-HTML链交标志中(<A HREF=>)
参考资料来源:百度百科-javascript
为什么非要ID呢,class不是更好吗?要知道,ID一般为唯一性质的
<div class="btn">
<a class="ReplyBtn" data-id="{$aaaid}">回复</a>
</div>
$("btn")on("click","aReplyBtn",function(){
var id=$(this)attr("data-id");
alert(id);
});
区别不同就在ID上,回复不同的内容对应ID
第一种方法就是自己写个方法获取所有的标签元素,在根据属性name的值去筛选
第二种方法就是documentquerySelectorAll()方法
例如你要查询所有name="ok"的标签
documentquerySelectorAll('[name="ok"]')
这样就可以了
望采纳
发现答非所问的人还不少啊
取父窗口的元素方法:$(selector,
windowparentdocument);
那么你取父窗口的父窗口的元素就可以用:$(selector,
windowparentparentdocument);
类似的,取其它窗口的方法大同小异
$(selector,
windowtopdocument);
$(selector,
windowopenerdocument);
$(selector,
windowtopframes[0]document);
希望对你能有帮助
<script type="text/javascrpt">
function setA()
{
//声明一个变量ahrefstr
var ahrefstr="";
//先得到ID为"ahref"的div中每个A标签(会是一个数组)
var myahref=documentgetElementById("ahref")getElementByTagName("a");
//循环得到每个a的href
for(i=0;i<myahref;i++)
{
//将得到的每一个ahref追加到全局变量ahrefstr中
ahrefstr+=myahref[i]hreftostring()+"\\n";
}
//d出
alert(ahrefstr);
}
</script>
每个Img规定一个ID;
<img src="1jpg" id="img1">
<img src="1jpg" id="img2">
<img src="1jpg" id="img3">
点击一个按钮获取src
<input type="button" value="获取src" onclick="aa()">
js中:
function aa(){
var img1 = documentgetElementById("img1")src;
//别的一样获取。这样获取的src是绝对路径
}
或者这样:
function aa(){
var img1 = documentgetElementById("img1")getAttribute("src");
//跟上面效果一样。
}
CSS的样式分为三类:
内嵌样式:是写在Tag里面的,内嵌样式只对所有的Tag有效。
内部样式:是写在HTML的里面的,内部样式只对所在的网页有效。
外部样式表:如果很多网页需要用到同样的样式(Styles),将样式(Styles)写在一个以css为后缀的CSS文件里,然后在每个需要用到这 些样式(Styles)的网页里引用这个CSS文件。
getComputedStyle是一个可以获取当前元素所有最终使用的CSS属性值。返回的是一个CSS样式对象([object CSSStyleDeclaration])
currentStyle是IE浏览器的一个属性,返回的是CSS样式对象
element指JS获取的DOM对象
elementstyle //只能获取内嵌样式
elementcurrentStyle //IE浏览器获取非内嵌样式
windowgetComputedStyle(element,伪类) //非IE浏览器获取非内嵌样式
documentdefaultViewgetComputedStyle(element,伪类)//非IE浏览器获取非内嵌样式
注:Gecko 20 (Firefox 4 / Thunderbird 33 / SeaMonkey 21) 之前,第二个参数“伪类”是必需的(如果不是伪类,设置为null),现在可以省略这个参数。
下面的html中包含两种css样式,id为tag的div是内嵌样式,而id为test的div样式为内部样式
<!doctype html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="Yvette Lau">
<meta name="keywords" content="样式,属性,字符串,内嵌,对象">
<meta name="description" content="可以参考下面的代码:<style>a{display:block;float:left}</style><div style="border:1px solid #cccccc">&l">
<title>Document</title>
<style>
#test{
width:500px;
height:300px;
background-color:#CCC;
float:left;
}
</style>
</head>
<body>
<div id = "test"></div>
<div id = "tag" style = "width:500px; height:300px;background-color:pink;"></div>
</body>
</html><script type = "text/javascript">
windowonload = function(){
var test = documentgetElementById("test");
var tag = documentgetElementById("tag");
//CSS样式对象:CSS2Properties{},CSSStyleDeclaration
consolelog(teststyle); //火狐返回空对象CSS2Properties{},谷歌返回空对象CSSStyleDeclaration{}
consolelog(tagstyle); //返回CSS2Properties{width:"500px",height:"300px",background-color:"pink"}
//elementstyle获取的是内嵌式的style,如果不是内嵌式,则是一个空对象
consolelog(tagstylebackgroundColor);//pink
consolelog(tagstyle['background-color']);//pink
//获取类似background-color,border-radius,padding-left类似样式的两种写法啊
consolelog(testcurrentStyle) //火狐和谷歌为Undefined,IE返回CSS对象
consolelog(windowgetComputedStyle(test,null))//谷歌返回CSSStyleDeclaration{……} ,火狐返回CSS2Properties{……}
consolelog(windowgetComputedStyle(test))
//效果同上,但是在Gecko 20 (Firefox 4/Thunderbird 33/SeaMonkey 21) 之前,第二个参数“伪类”是必需的(如果不是伪类,设置为null)
consolelog(testcurrentStylewidth);//500px(IE)
consolelog(windowgetComputedStyle(test)width); //500px;
consolelog(windowgetComputedStyle(test)['width']);//500px;
//documentdefaultViewgetComputedStyle(element,null)[attr]/windowgetComputedStyle(element,null)[attr]
}
</script>
以上就是关于js获取css属性,更改margin-top属性,给每个a标签的margin-top属性在原基础上 +5px全部的内容,包括:js获取css属性,更改margin-top属性,给每个a标签的margin-top属性在原基础上 +5px、jquery,js获取a标签id属性、在js中怎样获取含有相同name属性的标签里的内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)