jQuery获取this当前对象子元素对象的方法
程序员文章站
2022-04-24 12:54:54
...
如下所示:
<select id="city"> <option value="beijing">北京</option> <option value="shanghai">上海</option> <option value="shenzhen">深圳</option> </select> $(function(){ $("#city").change(function(){ ①// 已获取select为当前this元素 }) })
如果想要在①获取选中option的值可以有如下方法
$("#city option:selected").val(); //使用选择器 $(this).children('option:selected').val() //使用this
有时候我们会想当然的这样写 $(this “a”), $(“this a”)之类,这样是不对的
上一篇: DOM案例分享—jQ实现点击任意位置关闭某处的效果
下一篇: 关于HTML5你不得不知的事
推荐阅读
-
JS与jQuery实现子窗口获取父窗口元素值的方法
-
在JavaScript中重写jQuery对象的方法实例教程_jquery
-
关于Jquery获取对象的属性与值
-
在JavaScript中重写jQuery对象的方法实例教程_jquery
-
JS获取节点的兄弟,父级,子级元素的方法_javascript技巧
-
JScript内置对象Array中元素的删除方法_javascript技巧
-
PHP使用mysql_fetch_object从查询结果中获取对象集的方法_PHP教程
-
Java之反射第十八天( --反射----类的加载--获取对象属性( 成员变量和方法)-- 构造方法 )
-
spring中通过ApplicationContext getBean获取注入对象的方法实例
-
js遍历json对象所有key及根据动态key获取值的方法(必看)