0

フォーム名を関数に渡し、それらが読み取られたことを確認して削除した後、アクションを変更してフォームを送信します。

function deletePhone(myForm){
   var r=confirm('Are you sure you want to delete this phone?');
   if(r==true){
       $(myForm).attr("action","index.cfm?deleteThis=1");
       $(myForm).submit();
   }
}

currentrowは、複数のフォームを作成していて、フォームのcurrentCountを保持しているため、使用している変数です。

   <a href="javascript:deletePhone('EditPhone_form_#currentrow#');">X Delete Phone</a>

例:

  • EditPhone_form_1
  • EditPhone_form_2
  • EditPhone_form_3
  • EditPhone_form_4
4

3 に答える 3

1

IDに基づいてjQueryルックアップを実行している場合、正しくフォーマットされていないようです。

これを試して:

   function deletePhone(myForm){
       var r=confirm('Are you sure you want to delete this phone?');
       if(r==true){
          $('#'+myForm).attr("action","index.cfm?deleteThis=1");
          $('#'+myForm).submit();
       }
    }

追加された#に注意してください

編集:フォームのHTML全体を投稿していませんが、おそらくタグはフォーム自体にありますよね?はいの場合は、これを試すこともできます:

<a href="javascript:deletePhone($(this));">X Delete Phone</a>

   function deletePhone(link){
       var r=confirm('Are you sure you want to delete this phone?');
       if(r==true){
          var form = link.closest('form');
          form.attr("action","index.cfm?deleteThis=1");
          form.submit();
       }
    }
于 2012-09-20T12:44:14.373 に答える
0

アクションを変更する代わりに、フォームに非表示フィールドを追加できます。そして、フォームの名前である$("[name='"+myForm+"']")場合は、要素に使用する必要があります。myForm

$("[name='"+myForm+"']").append("<input type='hidden' value=1 name=deleteThis />");

したがって、コードは次のようになります。

 function deletePhone(myForm){
       var r=confirm('Are you sure you want to delete this phone?');
       if(r==true){
          $("[name='"+myForm+"']").append("<input type='hidden' value=1 name=deleteThis />");
          $("[name='"+myForm+"']").submit();
       }
    }
于 2012-09-20T12:41:56.240 に答える
0

onclickイベントを使用する代わりにjQueryイベントバインディングを使用しているようです。

function deletePhone(e){
    e.preventDefault();
    var r = confirm('Are you sure you want to delete this phone?');
    if(r){
        $(this)
            .closest('form')
            .attr("action","index.cfm?deleteThis=1")
            .submit();
    }
}

$(".remove-phone").on("click", deletePhone);

次のようなマークアップを使用します。

<a href="#" class="remove-phone">X Delete Phone</a>
于 2012-09-20T14:02:31.817 に答える