自定义 jQuery 不适用于 Wordpress Ninja Forms 插件 [英] Custom jQuery not working on Wordpress Ninja Forms plugin

查看:20
本文介绍了自定义 jQuery 不适用于 Wordpress Ninja Forms 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想添加影响表单的自定义 jQuery 代码时遇到了一些问题.

I am having some problems when I want to add custom jQuery code that affects the form.

例如,当有人点击一个输入或单选按钮时,另一个输入或元素将被隐藏或显示.我试图得到类似 console.log('trigger'); 当点击或其他东西的结果其他但在开发中什么都没有.控制台出现了.另外,我尝试了以下方法:

For example when someone clicks an input or radio button another input or element to be hidden or shown.I tried to get a result like console.log('trigger'); when clicked or something else but nothing in dev. console appeared.Also, I tried the following methods:

使用 .on('click', function()... 调用 click 事件或使用 .trigger('click');,或将事件更改为 change

To call the click event with .on('click', function()... or to call the event with .trigger('click');, or to change the event to change

将脚本嵌入到忍者表单的文件中或将其放在页面中 footer.php

To embed the script within a file from ninja forms or to put it inside the page at the ending of body tag in footer.php

改变 jQuery 的开始声明以在这样的函数中工作: (function($) {$(document).ready(function(){.....

To change the opening declaration of jQuery to work inside a function like this : (function($) {$(document).ready(function(){.....

我知道我可以尝试另一个插件,我尝试了一个并且自定义 jQuery 可以工作,但我真的很喜欢这个,但不知道为什么会这样......

I know that I could try another plugin, I tried one and the custom jQuery works but I really like this one and don't know why this is happening ...

谢谢

推荐答案

不确定您是否还需要这方面的帮助,因为您发布问题已经有一段时间了,但这可能会在未来对其他人有所帮助.我遇到了相同/类似的问题,无法在 Ninja Forms 上运行 JS/jQuery,并发现这是因为 Ninja Forms 异步加载它们的表单.因此,当您的 document.ready 函数运行时,该表单尚不存在且无法绑定.

Not sure if you need help with this any more as it's been some time since you posted your question, but this may help others in the future. I had the same/similar issue with not being able to run JS/jQuery on the Ninja Forms and found that it's because Ninja Forms load their forms asynchronously. So, when your document.ready function runs, the form doesn't yet exist and it's not able to bind.

Ninja Forms 有自己的事件就绪状态,可以如下使用:

Ninja Forms have their own event ready state that can be used as follows:

jQuery(document).on( 'nfFormReady', function( e, layoutView ) {
    // Your code goes here...
});

这篇关于自定义 jQuery 不适用于 Wordpress Ninja Forms 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆