简体   繁体   English

如何调用触发器。(“单击”)

[英]How to call trigger.('click')

<div class="kn-submit">

<input type="hidden" name="parent_object" value="">
<input type="hidden" name="parent_field" value="field_510">
<input type="hidden" name="parent_id" value="">

<input name="view_key" type="hidden" value="view_848">
<input name="view_name" type="hidden" value="Edit OperationNu">

<input type="submit" value="Submit">   
<div class="kn-spinner" style="display: none"></div>

$('.kn-submit').trigger('mousedown');// those 2 doesnt give results :(
$('.kn-submit').trigger('click');

My issue is that I want to make this button autoclick when specific function is called Calling trigger on the class doesn't have any effects 我的问题是,当调用特定函数时,我想使此按钮自动单击。在类上调用触发器没有任何效果。

You are trying to trigger on div element. 您正在尝试在div元素上触发。 You need to trigger click on submit button in this div . 您需要在此div触发单击“ submit按钮。

Change it to: 更改为:

$('.kn-submit input[type="submit"]').trigger('click');

And you dont need this: 而且您不需要这个:

$('.kn-submit input[type="submit"]').trigger('mousedown');

But also if you want just submit the form, use your form id and call this: 而且,如果您只想提交表单,请使用表单id并调用此代码:

$('#form_id').submit();

To auto submit the form: 自动提交表单:

<form id="myform" action="target.php" method="post">
<input type="hidden" name="parent_object" value="">
<input type="hidden" name="parent_field" value="field_510">
<input type="hidden" name="parent_id" value="">

<input name="view_key" type="hidden" value="view_848">
<input name="view_name" type="hidden" value="Edit OperationNu">

<input type="submit" value="Submit"> 
</form>

<script>
  $('#myform').submit();
</script>

Put the class name in the submit button. 将班级名称放在“提交”按钮中。 Also use the anonymous functions because you are calling the trigger function but you are not telling it what to do. 也请使用匿名函数,因为您正在调用触发器函数,但没有告诉它该怎么做。 Here is two ways you can proceed after you fix the class name: 修复类名称后,可以通过以下两种方法继续进行操作:

Method 1: 方法1:

$(".kn-submit").trigger("click", function(){
     // what you want to do
});//trigger function

Method 2: 方法2:

$(".kn-submit").click(function(){
     // what you want to do
});//click function

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

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