这个问题似乎在 Stack Overflow 上被问了很多,但似乎没有一个解决方案有效。我正在开发一个 Web 应用程序,我必须在页面加载时在数据字段中填写数据。这是我的代码:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<input type="text" id="datetime" value="" />
<script type="text/javascript">
$(document).on("pageload",function(){
//for fill field
document.getElementById("datetime").value = "here is value";
});
</script>
</body>
</html>
由于某种原因,当我加载页面时,没有填写任何数据,有人知道这是什么原因吗?
最佳答案
您不需要 jQuery。试试这个:
<!DOCTYPE html>
<html>
<body>
<input type="text" id="datetime" value="" />
<script>
window.onload = function() {
document.getElementById('datetime').value = 'here is value';
};
</script>
</body>
</html>
关于javascript - 如何在页面加载时直接使用 Javascript 在输入字段中填写数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36673634/