2012-04-03 3 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"/> 

Ich versuche, den Wert, der im Titel Attribut der Auswahl ist, aber ich kann nur den aktuellen Wert auswählen. Weiß jemand, wie man das löst? Verwenden Sie diesen Code unten:Wie erhalte ich den aktuellen Wert des title-Attributs in einem Select?

$("#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 
    }); 

Antwort

2

Versuchen

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

nicht. Wenn ich sehe, dass Ihr Code unvollständig ist. – Karra

+0

Es funktioniert ganz sicher. http://jsfiddle.net/jfeltis/9zkJZ/ – Joe

0

Das in meinem Fall gearbeitet:

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