[英]How to set a initial value for a text field in a form? This value is generated from a javascript function. How can i define the event without botton?
<body onload="onload();">
<input type="text" class="input-field" id="test" title="TEST" />
</body>
This is the javascript to generate a value for the text field. 这是用于为文本字段生成值的javascript。
<script language="javascript" type="text/javascript">
function onload()
{
var a=0;
a++:
document.getElementById("test").value=a;
}
</script>
You can use a body onload event, 您可以使用body onload事件,
http://www.w3schools.com/tags/ev_onload.asp http://www.w3schools.com/tags/ev_onload.asp
or a jquery onload event: 或jquery onload事件:
Why don´t you use one of this functions? 为什么不使用其中一个功能?
$(document).ready(function() {
var a=0;
a++;
document.getElementById("test").value=a;
});
OR 要么
$(window).load(function() {
var a=0;
a++;
document.getElementById("test").value=a;
});
Both of them start when the page is loaded. 两者都在页面加载时启动。
By the way... in this case a
will always be 1 顺便说一句...在这种情况下,
a
将始终为1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.