[英]Using Play 2 framework drop down list with jQuery or JavaScript
I am new to play framework so please bear with me. 我是玩框架的新手,请耐心等待。 Can some one explain to me how to access an item selected in a play 2 framework drop down list, using a jQuery function? 有人可以向我解释如何使用jQuery函数访问在play 2框架下拉列表中选择的项目吗?
For example: 例如:
<select class = "selectone">
@for(gesture <- gesturesList){
<div class = "gesture" > <option value = @gesture.id>
@gesture.getName()
</option>
</div>}
</select>
The above drop down list is populated by the following function: 上面的下拉列表由以下功能填充:
public static Result gesture()
{
List <Gesture> gcet = Gesture.find.orderBy("name asc").findList();
return ok(views.html.train.render(gcet));
}
I want to access the selected item using jQuery or maybe JavaScript. 我想使用jQuery或JavaScript访问所选项目。 Any suggestion. 任何建议。
Unless I misunderstood, that's nothing to do with Play, it's pure Jquery: 除非我误解了,否则与Play无关,它就是纯Jquery:
//uses a class selector to get the selected value in the dropdown
$(".selectone").val();
That said, you are adding a div
in your select, it shouldn't be like that. 也就是说,您要在选择中添加一个div
,它不应该那样。 Your code should be: 您的代码应为:
<select class = "selectone">
@for(gesture <- gesturesList){
<option value = @gesture.id>
@gesture.getName()
</option>
}
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.