请在此处找到代码 - https://github.com/iamanandkris/RedirectURL/blob/master/app/views/editRedirect.scala.html。我正在尝试将输入1,2和3的内容打印到div中,当焦点从这3个对象中的任何一个更改时。我能够看到,当焦点发生变化时,java脚本也会被调用,并且能够获得警报。我可以填充以下3个值
var idToGet = document.getElementById('uid').value
var qargsToGet = document.getElementById('qargs').value
var rurlToGet = document.getElementById('rurl').value
但声明不起作用
var s= document.getElementById('thecurrenturl');
s.html = "testing again";
请通过以下完整代码:
@(redirectForm: Form[RedirectModel])(implicit flash: Flash, lang: Lang)
@import helper._
@import helper.twitterBootstrap._
@main(Messages("products.form")) {
<h2>@Messages("products.form")</h2>
@helper.form(action = routes.Redirects.save()) {
<fieldset>
<label for="targetURL">Target URL: </label>
<div id="thecurrenturl"></div>
<legend>
@Messages("products.details", Messages("products.new"))
</legend>
@inputText(
redirectForm("uid"), '_label -> "User ID",'onBlur->"myFunction()",'_help -> "Enter a valid user id."
)
@textarea(
redirectForm("qargs"), 'onBlur->"myFunction()"
)
@textarea(
redirectForm("rurl"), 'onBlur->"myFunction()"
)
</fieldset>
<p><input type="submit" class="btn primary"
value='@Messages("products.new.submit")'></p>
}
<script type="text/javascript">
var successFn = function(data) {
console.debug("Success of Ajax Call");
console.debug(data);
};
var errorFn = function(err) {
console.debug("Error of ajax Call");
console.debug(err);
}
ajax1 = {
success: successFn,
error: errorFn
}
function myFunction() {
alert("test")
var idToGet = document.getElementById('uid').value
var qargsToGet = document.getElementById('qargs').value
var rurlToGet = document.getElementById('rurl').value
var s= document.getElementById("thecurrenturl");
s.html = "testing again";
alert(idToGet+'/'+qargsToGet+'/'+rurlToGet)
jsRoutes.controllers.Redirects.getString()
.ajax(ajax1);
}
</script>
}
答案 0 :(得分:2)
更改以下行
s.html = "testing again";
到
s.innerHTML = "testing again";
html 是一个jQuery函数。