简体   繁体   English

WordPress表单,无法使用jQuery设置值

[英]Wordpress form, cannot set value with jQuery

I've designed a simple form in Wordpress which I included (as HTML) in an external file [see background at the end] . 我在Wordpress中设计了一个简单的表单,该表单包含(作为HTML)在一个外部文件中(请参阅最后的背景) In this file, an event listener is supposed to fill an input of the form. 在此文件中,应该使用事件侦听器填充表单的输入。 But I cannot set a value in this input, the change doesn't seem to be made. 但是我无法在此输入中设置值,似乎未进行更改。

Here is the input (as generated with Wordpress) : 这是输入(由Wordpress生成):

<span class="wpcf7-form-control-wrap tarif-depart">
     <input name="tarif-depart" value="" size="40" class="wpcf7-form-control wpcf7-text tarif-hidden" id="tarif-depart" aria-invalid="false" type="text">
</span>

And here is the JS : 这是JS:

$('#tarif-depart')
    .val(places.O[0].formatted_adress)

Background 背景

I'm working on a little script using Google Map API on a Wordpress site. 我正在使用Wordpress网站上的Google Map API编写一个小脚本。 The fact is including my script (and HTML elements) doesn't seem to work well when integrated. 事实是,包括我的脚本(和HTML元素)在集成时似乎无法很好地工作。 So, I chosed to include it inside an iframe. 因此,我选择将其包含在iframe中。 The script is related to a form that I had to add in the iframe for communication. 该脚本与我必须添加到iframe中进行通信的表单有关。 But it doesn't work better ... 但这并不能更好地工作...

Thanks for your help. 谢谢你的帮助。

If you are writing jQuery in a PHP document (like Wordpress) you need to write it as 如果要在PHP文档(如Wordpress)中编写jQuery,则需要将其编写为

jQuery('#tarif-depart')
    .val(places.O[0].formatted_adress)

or wrap it in a wrapper like this: 或像这样包装在包装纸中:

jQuery(document).ready(function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut
});

source for the last bit 最后一点的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM