2

I am trying to something very simple. I have this select tag

<select id="appID">
<option value="1409608204102">test app 1</option>
<option value="1409608295422">test set 2</option>                       </select>

I want to print the text of the selected option in the "printHere" div. Very simple but for some reason I cant figure out how to do it through jquery

I am doing this but

$('#appID').change(function(){
               var k = $(this).is('selected','selected').text();
               $('.printHere').text(k);
           });
4

3 回答 3

4

您可以使用

var k = $(':selected', this).text();

k将是"test app 1""test set 2"

于 2013-06-26T18:39:32.490 回答
1

尝试使用:selected

var k = $(this).find(':selected').text();
于 2013-06-26T18:40:17.460 回答
0

只需将其他海报所说的内容添加到您的工作示例中即可。 http://jsfiddle.net/kshreve/P6qbp/2/

var k = $(this).find(':selected').text();
$("div").text(k);
于 2013-06-26T18:50:38.927 回答