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例子:
对应的javascript dom代码为:
--EOF--
网址: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--
相关文章推荐
- JAVA问题总结之26-异常处理
- SpringMVC接收数组请求参数小技巧
- php实现的单一入口应用程序实例分析
- spring自定义事件监听
- Lua常用字符串操作
- 我叒玩坏eclipse以后决定把问题记录下来了
- Java之旅Struts系列(2)——Struts1(精华)
- Java 7 中 NIO.2 的使用——第一节 Path 类的使用
- 生产者消费者问题(thinking in java 709 )
- Spring事务配置及事务传播隔离级别
- c++ this指针
- C语言符号控制命令表
- mysql和eclipse都设置了utf8编码,保存时中文依然乱码
- 根据java编译器规则在Class中搜索匹配指定参数类型表的泛型方法(GenericMethod)
- C++杂记
- thriftのjava应用
- Spring MVC Interceptors 如何被调用
- Eclipse中使用Gradle进行打包APK问题总结
- C++设计模式——桥接模式
- 【Java EE 学习 48】【Hibernate学习第五天】【抓取策略】【二级缓存】【HQL】