jQuery:如何获取id属性的值? [英] jquery: how to get the value of id attribute?

查看:326
本文介绍了jQuery:如何获取id属性的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本的jquery问题.我有一个如下的选择元素.

Basic jquery question. I have an option element as below.

<option class='select_continent' value='7'>Antarctica</option>  

jquery

$(".select_continent").click(function () {
  alert(this.attr('value'));
});

这会给出一个错误,说this.attr不是一个函数,因此我没有正确使用"this".

This gives an error saying this.attr is not a function so im not using "this" correctly.

我如何使它发出7号警报?

How can i get it to alert 7?

推荐答案

您需要这样做:

alert($(this).attr('value'));

这篇关于jQuery:如何获取id属性的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆