2012-04-03 6 views
0
<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

... 
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 
... 
+0

は機能しません。あなたのコードが不完全であることがわかります。 – Karra

+0

これは確かに動作します。 http://jsfiddle.net/jfeltis/9zkJZ/ – Joe

0

これを試してみてください私の場合で働いていた:

var data1 = $('#select_id>option:selected').attr('title'); 
$("input#city").val(data1); 
関連する問題