[英]Function to hide form fields from external script
I'm using a web page which contains a form loaded with an external script using the command 'script src'.我正在使用 web 页面,其中包含使用命令“script src”加载了外部脚本的表单。
I created a function to populate some fields from url parameters and also hide some of them.我创建了一个 function 来填充 url 参数的一些字段并隐藏其中一些。
Here is the code.这是代码。
<script type="text/javascript">
<!-- Hide Form Field -->
function hideFormField(name) {
var list = document.getElementsByName(name);
for (i = 0; i < list.length; i++) {
list[i].style.display = 'none';
list[i].style.visible = 'false';
list[i].type = 'hidden';
}
}
<!-- Customize form -->
function CustomizeForm()
{
// Set Field Value
hideFormField('custom_11');
hideFormField('custom_12');
hideFormField('custom_13');
hideFormField('custom_14');
hideFormField('custom_15');
}
// call it
CustomizeForm();
</script>
The fields are populated but not hidden.这些字段已填充但未隐藏。
When I debug, the form fields appear to disappear briefly but then they reappear.当我调试时,表单字段似乎会短暂消失,但随后又会重新出现。
It looks like the form is being refreshed afterwards.看起来表单正在被刷新。
field.style.display = 'none';
field.style.visible = 'false';
field.type = 'hidden';
Where should I put the call to the function to hide fields?我应该在哪里调用 function 来隐藏字段?
Assuming I don't control where the code is being added exactly in my designer (only in which section: header, body or footer), is there another alternative that would work every time?假设我不控制在我的设计器中准确添加代码的位置(仅在哪个部分:header,正文或页脚),是否有另一种每次都可以使用的替代方法? For example, can I attach to an event (which one) that might get called after all the loading and refresh is done.
例如,我可以附加到在所有加载和刷新完成后可能被调用的事件(哪个)。
Can I somehow debug or trace what is happening and why the fields do reappear?我可以以某种方式调试或跟踪正在发生的事情以及为什么这些字段会重新出现吗?
Thank you in advance!先感谢您!
it's visibility not visible , try:它的可见性不可见,请尝试:
list[i].style.visibility = "hidden";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.