如何在select中获取title属性的当前值?

时间:2012-04-03 18:56:09

标签: select title

<select name="alb_id" id="select_id">
  <option value="0">:: Selecione um álbum ::</option>
  <option title="My first title" value="40">First</option>
  <option title="My second title" value="41">Second</option>
  <option title="My third title" value="59">Third</option>
</select>
<input type="submit" value="Alterar" id="btsend" name="send" class="btedit"/>

我正在尝试获取select的title属性中的值,但我只能获取当前的选择值。有谁知道如何解决这个问题?请使用以下代码:

$("#btsend").click(function (e) {
    var get_val = $("#select_id").val($(this).find("option:selected").attr("title"));
    $("#new_value").val(get_val); //$new_value: I want to here the value of the selected option's title
    });

2 个答案:

答案 0 :(得分:2)

尝试

...
var get_val = $('#select_id>option:selected').attr('title');
$("#new_value").text(get_val); //$new_value: I want to here the value of the selected option's title
...

答案 1 :(得分:0)

这适用于我的情况:

var data1 = $('#select_id>option:selected').attr('title');
$("input#city").val(data1);