[英]how can i control the submit button with JS function in html form
[英]How can I insert result of JS function in html form?
我有一个问题-如何以html格式插入JS函数的结果? 我需要将时间(以hh:mm格式)放入“值”表格中。 JS代码:
function getHours() {
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
document.getElementById('clientid').value=h+" "+m;}
HTML形式:
<html>
<form method='post' action='http.example.com/some.php'>
<input type='hidden' name='clientid' id='clientid' value="test" action="javascript:getHours()" />
</form>
</html>
感谢您的关注!
您需要像这样加载函数:
<html>
<body onload="getHours()">
<form method='post' action='http.example.com/some.php'>
<input type='hidden' name='clientid' id='clientid' value="test" action="javascript:getHours()" />
</form>
<script>
function getHours() {
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
document.getElementById('clientid').value = h + " " + m;
}
</script>
</body>
</html>
$time = h + ':' + m ;
$('#clientid').val($time);
$time = h + ':' + m ;
将小时和分钟添加到$time
变量所需的格式。
之后$('#clientid').val($time);
告诉JS将变量添加到clientid的值中。
您可以使用onload()
方法调用函数getHours()
,但.onload()
支持以下tags
:
<body>, <frame>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>
尝试这个
<script> document.addEventListener("DOMContentLoaded", function(event) { var name = "Beginner"; document.getElementById("clientid").setAttribute("value", name); }); </script> <input name='clientid' id='clientid' />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.