2016-03-01 31 views
-1

我在使用兩個插件時遇到了問題。我曾嘗試:髒格式jQuery插件問題

https://github.com/snikch/jquery.dirtyforms

https://github.com/codedance/jquery.AreYouSure

在我的代碼我使用:

<script> 
    $(funtion() { 
     $('form').dirtyForms(); 
    }); 
</script> 

或者

<script> 
    $(funtion() { 
     $('form').areYouSure(); 
    }); 
</script> 

我的頭內,當我改變的元素形式和嘗試刷新我沒有得到dialouge。我正在努力研究如何判斷它是否被調用。

我不能爲我的生活得到它的工作。有任何想法嗎?

下面是一個頁面的查看源代碼例子用在:

<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 

     <link rel="icon" href="favicon.ico" type="image/x-icon"> 
     <link rel="stylesheet" href="styles/header.css?v=1.0"> 
     <link rel="stylesheet" href="styles/content.css?v=1.0"> 
     <link rel="stylesheet" href="styles/footer.css?v=1.0"> 
     <link rel="stylesheet" href="styles/jquery.datetimepicker.css?v=1.0"> 

     <script src="scripts/jquery191.min.js"></script> 
     <script src="scripts/mdetect.js" type="text/javascript"></script> 

     <script type="text/javascript"> 

      if(MobileEsp.DetectTierIphone() == true) { 
       var metaTag=document.createElement('meta'); 
       metaTag.name = "viewport" 
       metaTag.content = "width=device-width, initial-scale=0.4, maximum-scale=1.0, user-scalable=1" 
       document.getElementsByTagName('head')[0].appendChild(metaTag); 
      } 

      if(MobileEsp.DetectTierTablet() == true) { 
       var metaTag=document.createElement('meta'); 
       metaTag.name = "viewport" 
       metaTag.content = "width=device-width, initial-scale=0.75, maximum-scale=1.0, user-scalable=1" 
       document.getElementsByTagName('head')[0].appendChild(metaTag); 
      } 

     </script> 

     <script type="text/javascript" src="scripts/jquery.tablesorter.js"></script> 
     <script type="text/javascript" src="scripts/jquery.tablesorter.widgets.js"></script> 
     <script type="text/javascript" src="scripts/widget-print.js"></script> 

     <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTHOXfueJyei11NqPw3rRjhjj_yjcdV-E&callback=initMap"></script> 

     <script src="scripts/jquery.datetimepicker.full.min.js"></script> 
     <script src="scripts/jquery.form.js"></script> 
     <script type="text/javascript" src="//cdn.jsdelivr.net/jquery.dirtyforms/2.0.0/jquery.dirtyforms.min.js"></script> 

     <script type="text/javascript" language="JavaScript"> 
      <!-- 
      function HideContent(d) { 
       document.getElementById(d).style.display = "none"; 
      } 
      function ShowContent(d) { 
       document.getElementById(d).style.display = "block"; 
      } 
      function ReverseDisplay(d) { 
       if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; } 
       else { document.getElementById(d).style.display = "none"; } 
      } 
      //--> 
     </script> 

     <script> 
     $(document).ready(function(){ 
      $("BodyshopAddress").each(function(){       
       var embed ="<iframe width='200' height='200' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' style='margin-left:30px;' src='https://maps.google.com/maps?&amp;q="+ encodeURIComponent($(this).text()) +"&amp;output=embed&iwloc'></iframe>"; 
       $(this).html(embed); 
      }); 
     }); 
     </script> 

     <script> 
      $(funtion() { 
       $('form').dirtyForms(); 
      }); 
     </script> 

     <!--[if lt IE 9]> 
     <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
     <![endif]--> 
    </head> 

    <body>  

    <div class="container"> 
      <div class="MainHeader"> 
       ... 
      </div> 
      <div class="logged_container"> 
       ... 
      </div> 
      <div class="navigation_container">   
       ... 
      </div> 

     <div style="position:absolute; top:0; right:0; margin-right:10px; margin-top:5px; background-color:#4771A5; border-radius:3px; padding:5px; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 25px rgba(82, 168, 236, 0.7);"> 
      <form id="myForm" action="" method="POST"> 
       <input type='text' size='20' name='Poke' placeholder='Magic Poking Stick' style="margin-right:5px; vertical-align:middle; text-align:center;">&nbsp;<input type='submit' name='BadBoyPoke' value='' class='submit' title='Search' maxlength="3" style='background-image:url(&quot;img/bms121.png&quot;); vertical-align:middle;' > 
      </form> 
     </div> 

     <script> 
      $(document).ready(function() 
       { 
        $('#RepairerNetworkTable').tablesorter({ 
         widthFixed : true, 
         headerTemplate : '{content} {icon}', // Add icon for various themes 
         widgets: [ 'stickyHeaders', 'filter', 'print' ], 
         widgetOptions: { 
          stickyHeaders_attachTo : '.wrapper', 

          print_title  : '',   // this option > caption > table id > "table" 
          print_dataAttrib : 'data-name', // header attrib containing modified header name 
          print_rows  : 'f',   // (a)ll, (v)isible or (f)iltered 
          print_columns : 's',   // (a)ll, (v)isible or (s)elected (columnSelector widget) 
          print_extraCSS : '',   // add any extra css definitions for the popup window here 
          print_styleSheet : 'styles/tablePrint.css', // add the url of your print stylesheet 
          print_callback : function(config, $table, printStyle){ 
           $.tablesorter.printTable.printOutput(config, $table.html(), printStyle); 
          } 
         } 
        }); 

        $('.print').click(function(){ 
         $('.tablesorter').trigger('printTable'); 
        }); 
       } 
      ); 
     </script> 
        <div class="content"> 
         <div class="contentTableView"> 
          <a href="#" class="print" style="float:right; margin-right:20px;"> 
          <img src="img/bms91.png" alt="" height="16" style="vertical-align:top; padding-right:5px;">Print</a> 
         </div> 
         <br /><br /> 
         <div class="GridViewContainer wrapper"> 
           <table id="RepairerNetworkTable" class="tablesorter">       
            ... 
           </table> 
         </div> 
         <br /> 
         <div class="TabbedViewContainer"> 
          <div class="TabbedNavContainer"> 
           <div style="position: relative; top: 50%; transform: translateY(-50%);"> 
            <form action="" method="post"> 
             <a style="text-decoration:underline !important;" href="repairer_network.php?RepNetID=9&RepNetTab=Info">Info</a> 

             <a href="repairer_network.php?RepNetID=9&RepNetTab=WorkProviders">Work Providers/Brokers</a> 

             <a href="repairer_network.php?RepNetID=9&RepNetTab=Bodyshops">Bodyshops</a> 

             <input name="submitInfo" type="submit" value="Change Repairer Network's Info" /> 

           </div> 
          </div> 
          <div style="text-align:left; padding-left:10px; padding-top:10px;"> 
           <span style="font-size: 12px; font-weight:bold;">Repairer Network Info: </span> 
           <br /> 
           <hr size='1' style=" margin: 5px 10px 5px 0; "> 
           <table style="float:left;"> 
            <tr> 
             <td>Name: </td> 
             <td><input name="BusinessName" type="text" size="30" value="AI Claims Solutions (UK) Ltd"/> </td> 
            </tr> 
            <tr> 
             <td>Email: </td> 
             <td><input name="BusinessEmail" type="text" size="30" value=""/></td> 
            </tr> 
            <tr> 
             <td>Phone: </td> 
             <td><input name="BusinessPhone" type="text" size="30" value=""/></td> 
            </tr> 
           </table> 
            </form> 
          </div> 
         </div> 
         <br />    
        </div> 
     <div class="footer"> 
      ... 
     </div> 
    </div> 
</body> 
</html> 

回答

1

它的簡單易用。只需將以下行添加到頁面的ready函數中: $('form')。areYouSure(); Are You Sure? - A light "dirty forms" JQuery Plugin

$(document).ready(function(){ 
    $('form').areYouSure(); 
}); 

這就是插件怎麼說......這聽元素$(「形式」)(你可以使用一個ID或類)並在「事件」「areYouSure()」時,該插件將觸發...

+1

這不是問題。問題是,jQuery選擇器沒有附加到窗體標籤。我正在創建一個不同的問題,因爲這不是很清楚。 – Ryan

+1

對不起,我沒有正確地得到你。我認爲它在[onunload事件](http://www.w3schools.com/jsref/event_onunload.asp)上使用了一個監聽器,並檢查表單元素的stae,所以可能你會通過調用一個函數來模擬它的功能檢查該事件的表單內容... –

+1

原來我不得不使用類選擇器而不是嘗試使用標記選擇器。無論如何,嘗試+1。這很有幫助。 – Ryan