当“重力形式”出现时触发 jquery输入按钮被点击

发布于 2024-12-21 06:29:31 字数 1434 浏览 3 评论 0原文

我更新了这个问题,因为这可能是由于重力形式阻止了一个简单函数的工作。我这么说的原因是因为我尝试了很多选项(下面列出)来触发 jQuery 函数,但没有一个在应该起作用的时候起作用。

我有一个简单的函数,低于它 100% 有效...

var $contactButton  = $(".contact-slide a"),
    $contactSlide   = $("#horizon-slide");

function () {
    $contactSlide.stop().css("top","0");
};

很简单,但是当我的提交按钮被重力点击时,我试图触发这个函数。


这是 WordPress 重力形式输入标记...

<input type="submit" id="gform_submit_button_1" class="button gform_button" value="Send" tabindex="7"></input>


这些是我尝试过的所有脚本,但没有一个运行该函数...

脚本一

$("input#gform_submit_button_1").on('click', function () {
    $contactSlide.stop().css("top","0");
});

脚本二

$("input#gform_submit_button_1").click(function() {
    $contactSlide.stop().css("top","0");
});

脚本三

$("input#gform_submit_button_1").focus(function () {
    $contactSlide.stop().css("top","0");
});

< strong>脚本四

$("form#gform_1").submit(function(event) {
$contactSlide.stop().css("top","0");
});


我也尝试过......

return false; 

以及

return true;

上面的所有脚本,但它们都没有返回该函数。如果我将脚本设置为返回 false,则表单不会提交,但如果我设置为返回 true,则表单会提交,但该函数不会运行。


为什么会发生这种情况,我以为这是基本的事情?

感谢您的任何帮助。

I've updated the question because it may because of gravity forms which is stopping a simple function from working. The reason I say this is because I've tried so many options (listed below) to trigger a jQuery function, and none of them work when they should.

I have a simple function below which 100% works...

var $contactButton  = $(".contact-slide a"),
    $contactSlide   = $("#horizon-slide");

function () {
    $contactSlide.stop().css("top","0");
};

Simple as it gets, but I'm trying to trigger this when my submit button gets clicked from a gravity from.

This is the wordpress gravity forms input markup...

<input type="submit" id="gform_submit_button_1" class="button gform_button" value="Send" tabindex="7"></input>

These are all the scripts below that I've tried, but none of them run the function...

Script One

$("input#gform_submit_button_1").on('click', function () {
    $contactSlide.stop().css("top","0");
});

Script Two

$("input#gform_submit_button_1").click(function() {
    $contactSlide.stop().css("top","0");
});

Script Three

$("input#gform_submit_button_1").focus(function () {
    $contactSlide.stop().css("top","0");
});

Script Four

$("form#gform_1").submit(function(event) {
$contactSlide.stop().css("top","0");
});

I've also tried...

return false; 

and

return true;

on all of the scripts above, but none of them return the function. If I set the scripts to return false then the form does not submit, but if I set to return true, then form submits but the function does not run.

Why is this happening, I thought this would be basic stuff?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

跨年 2024-12-28 06:29:31

您是否想在提交表单时运行某些操作?如果您使用表单的 AJAX 提交方法,则可以使用 gform_confirmation_loaded 事件来提交表单后运行一些 JavaScript。

$(document).on('gform_confirmation_loaded', function(e, form_id){
   if(form_id == 2) {
       $contactSlide.stop().css("top","0");
   }
});

它将在每个表单提交上运行,因此要指定表单,请测试传递给事件处理程序的 form_id 参数。

Are you trying to have something run upon form submission? If you're using the AJAX submission method of the form you can use the gform_confirmation_loaded event to run some JavaScript after the form is submitted.

$(document).on('gform_confirmation_loaded', function(e, form_id){
   if(form_id == 2) {
       $contactSlide.stop().css("top","0");
   }
});

It will run on every form submission so to specify the form, test the form_id parameter passed to the event handler.

等往事风中吹 2024-12-28 06:29:31

如果您有表单,您可以通过表单提交来控制它。

<script type="text/javascript" src="js/jquery1.6.1.js"></script>
<script type="text/javascript">
 $(document).ready(function () {
   $("#forma").submit(function(event) {
       //do what ever you need to here
        return false;
    });
});
</script>
<form name="1stform" method="post" action="/">
    <input type="text" name="misc" id="misc" />
    <input type="submit" name="submit" id="submit" value="submit 1st form"/>
</form>

You can control it from the form submit if you have a form..

<script type="text/javascript" src="js/jquery1.6.1.js"></script>
<script type="text/javascript">
 $(document).ready(function () {
   $("#forma").submit(function(event) {
       //do what ever you need to here
        return false;
    });
});
</script>
<form name="1stform" method="post" action="/">
    <input type="text" name="misc" id="misc" />
    <input type="submit" name="submit" id="submit" value="submit 1st form"/>
</form>
早乙女 2024-12-28 06:29:31
$contactInput.focus(function () {
    $contactSlide.stop().css("top","0");
    $('body,html').animate({
        scrollTop: 0
    }, 0);
    return true;
});

尝试一下:)

$contactInput.focus(function () {
    $contactSlide.stop().css("top","0");
    $('body,html').animate({
        scrollTop: 0
    }, 0);
    return true;
});

Give it a try :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文