![](/img/trans.png)
[英]How to add a field and value to a post form before sending it in javascript?
[英]Add value to existing form field with javascript
我正在尝试添加以下代码的 output(在页面加载时)
<?php the_field('object_id'); ?>
到 id="sf_objekt" 的表单字段。 该字段具有可选的设置值“ID”。 代码的 output 应替换“ID”。
我尝试使用“追加”,但没有运气。
有任何想法吗? 泰!
如果我正确地理解了您的问题,那么以下代码段应该可以解决问题:
document.querySelector('#sf_objekt').value = "<?php the_field('object_id'); ?>"
<input id="sf_objekt" type="text" />
Clearly the <?php> tag will be replaced with the output of the PHP function the_field()
only if the page is ran through a PHP server.
此代码将使用 php 脚本的结果自动填写表格。
<html>
<body>
<form>
<input type="text" id="sf_objekt">
</form>
<script>
document.getElementById("sf_objekt").defaultValue= "<?php echo the_field('object_id'); ?>";
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.