您的位置:首页 > 编程语言

5位运动员参加了10米台跳水比赛,每位选手都说对了一半,请编程确定比赛的名次

2015-09-23 14:56 369 查看
作者:wasw100

网址:http://www.wasw100.com/html_js_css/jquery_attr_val.html

 

$(this).attr(key); 获取节点属性名的值,相当于getAttribute(key)方法

$(this).attr(key, value); 设置节点属性的值,相当于setAttribute(key,value)方法

 

$(this).val();获取某个元素节点的value值,相当于$(this).attr("value");

$(this).val(value);设置某个元素节点的value值,相当于$(this).attr("value",value);

 

jquery例子:

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery attr属性</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#iButton").click(function(){
alert($(this).attr("test"));	//获取test的属性
$(this).attr("test","abc");//设置test的属性为abc
alert($(this).attr("test"));
});
});
</script>
</head>
<body>
<input id="iButton" type="button" test="123" value="按钮" />
</body>
</html>

 对应的javascript dom代码为:

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>attribute属性</title>
<script type="text/javascript">
function attrTest(){
alert(document.getElementById("iButton").getAttribute("test"));
document.getElementById("iButton").setAttribute("test","abc");
alert(document.getElementById("iButton").getAttribute("test"));
}
</script>
</head>
<body>
<input id="iButton" type="button" test="123" value="按钮" onclick="attrTest();" />
</body>
</html>

 

--EOF--

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: