Javascript 加载页面时触发单击一次

Javascript 加载页面时触发单击一次,javascript,jquery,Javascript,Jquery,我的页面中有这样一个表单: <form id="shipping" action="some-action-url" method="post"> <ul> <li> <input id="ship238280" name="method" value="238280|479435" type="radio" checked="checked"> <label

我的页面中有这样一个表单:

     <form id="shipping" action="some-action-url" method="post">
        <ul>
         <li>
          <input id="ship238280" name="method" value="238280|479435" type="radio" checked="checked">
          <label for="ship238280">Transport (€0,00)</label>
         </li>
         <li>
          <input id="ship292259" name="method" value="292259|580109" type="radio">
          <label for="ship292259">Pick up (€0,00)</label>
         </li>
        </ul>
      </form>
以及单击其中一个选项时的单击事件:

 $('#shipping input').on('click', function(){
   sendform()
 });
我现在想要的是在页面加载时提交表单。所以我创造了这样的东西:

$(function(){
  $('#shipping input').each(function(){
    if($(this).is(':checked')){
      $(this).trigger('click') // or sendform()
     }
   });
});  
现在的情况是表单一直在提交,因为每次页面重新加载(提交后)它都想再次提交

知道需要先提交才能设置选项,我如何解决这个问题

我尝试了类似于ajax成功函数中的
$(document).one('ready',function(){
)或类似于
$(this).unbind()
的方法

我有点迷路了:)所以非常感谢您的帮助!!

试试这样的方法:


为什么不使用Ajax在不重新加载页面的情况下更改页面的内容?这会提交到哪里?表单数据存储在哪里?这个流程听起来很奇怪。解释shipping选项如何要求提交first@MickaelLeger:要设置选项,它需要将表单提交到url。让我们说“setshipment”。当这在系统中不起作用时tem设置了正确的选项。我没有访问权限。我可以使用ajax设置一个选项,但它不会加载到系统中,这样系统就知道设置了哪个选项。它确实必须提交到表单urlWell。也许你可以尝试使用一些cookie来知道表单是否已经发送,这样你就不会再这样做了是时候了?
$(function(){
  $('#shipping input').each(function(){
    if($(this).is(':checked')){
      $(this).trigger('click') // or sendform()
     }
   });
});  
$(document).ready(function(){
  if( localStorage.getItem('submited') !== '1' ){
    $('#myform').submit();
    localStorage.setItem('submited', '1');
  }
});