gpt4 book ai didi

javascript - 将 javascript 与模型表单结合使用

转载 作者:行者123 更新时间:2023-11-28 09:18:20 25 4
gpt4 key购买 nike

我从表单中获取值,并使用这些值在我的游戏项目中创建 Journey 对象,但我需要扩展它,以便我可以在后台添加其他值。下面是我当前的表单,它从用户输入中获取所有值。

@form(routes.Application.createJourney()) {

<fieldset>

@inputText(journeyForm("start_loc"), '_label -> "Starting Location", 'placeholder -> "E.g. 1 Main Street")
@inputText(journeyForm("end_loc"), '_label -> "End Location", 'placeholder -> "E.g. 1 High Street")
@select(
journeyForm("participant_type"),
options = options("Driver"->"Driver", "Passenger"->"Passenger"),
'_label -> "Travel as",
'_error -> journeyForm("participant_type").error.map(_.withMessage("Select participant type"))
)
@inputDate(journeyForm("date"), '_label -> "Date")
@helper.input(journeyForm("Time")) { (id,name,value,args) => <input type="time" name="@name" id="@id" @toHtmlArgs(args)> }

</fieldset>
<div class="actions">
<input type="submit" value="Create" class="btn primary">
</div>

我不太确定如何将 javascript 与这些 scala 模板生成器一起使用,并且我有一个我想使用的 javascript 函数。我的表单中的两个输入用于位置,我希望能够使用 javascript 检索这些位置,以使用 Google Maps API 获取其纬度/经度值。下面是一个位置的 javascript:

  <script type="text/javascript">
function codeAddress() {
var geocoder;
geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>

所以有两件事是我真正需要做的。从表单中检索 inputText 以在 javascript 函数中使用。在我的 javascript 函数中使用变量来填充后台的表单争论之一。通常我只会使用 document.getElementByID,但我认为这不适用于正在使用的表单助手?

最佳答案

您可以使用表单助手设置元素的 id。一旦在 View 中呈现,使用 JavaScript 检索它应该不成问题。

关于javascript - 将 javascript 与模型表单结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15348102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com