【发布时间】:2015-01-25 14:09:04
【问题描述】:
我试图做这个 jquery 选择的项目将显示在文本字段中但它不起作用,如果它在 div 中使用它代替使用 div 的输入文本但它不起作用以下代码作为文本字段
<html>
<head>
<style>
div {
color: red;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<select name="sweets" multiple="multiple">
<option>Chocolate</option>
<option selected="selected">Candy</option>
<option>Taffy</option>
<option selected="selected">Caramel</option>
<option>Fudge</option>
</select>
<input type="text" name="fname">
<script>
$( "select" )
.change(function () {
var str = "";
$( "select option:selected" ).each(function() {
str += $( this ).text() + " ";
});
$( "fname" ).text( str );
})
.change();
</script>
</body>
</html>
【问题讨论】:
标签: jquery input jquery-plugins