[英]How can I set the value of an Angular formcontrol field from Javascript?
[英]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>
這是用於為文本字段生成值的javascript。
<script language="javascript" type="text/javascript">
function onload()
{
var a=0;
a++:
document.getElementById("test").value=a;
}
</script>
為什么不使用其中一個功能?
$(document).ready(function() {
var a=0;
a++;
document.getElementById("test").value=a;
});
要么
$(window).load(function() {
var a=0;
a++;
document.getElementById("test").value=a;
});
兩者都在頁面加載時啟動。
順便說一句...在這種情況下, a
將始終為1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.