簡體   English   中英

需要幫助來使jQueryTools驗證腳本在沒有提交按鈕的情況下啟動

[英]Need help getting a jQueryTools Validation script to fire without a submit button

我有以下ColdFusion頁面(如下)。 我正在運行jQueryTools驗證。 它可以通過傳統的“提交”按鈕很好地工作,但是我需要它可以通過a href鏈接(格式為按鈕)來工作(在代碼中稍稍向下一點)。 我似乎無法弄清楚如何獲取通常提交表單的href鏈接以觸發將導致頁面在提交表單之前進行驗證的操作。

我的Java技術似乎很基礎。 任何幫助將不勝感激。

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><cfoutput>Welcome to#application.settings.meta_title#</cfoutput></title> <script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script> <link rel="stylesheet" href="/common/ext/jQuerytools/form.css" type="text/css" media="all" /> <style> /* error container */ #errors { background-color: #163356; color: #fff; width: 400px; padding: 20px; margin: 5px auto; display: none; -moz-border-radius: 5px; -webkit-border-radius: 5px; } /* title */ #errors h2 { margin: -5px 0; color: yellow; } </style> </head> <body onLoad="self.focus();"> <h1>Pre Incident Plans Editor</h1> <!--- BEGIN MAIN CONTENT AREA ---> <div id="main"> <div id="leftcol"> <form action="" method="POST" name="form2" id="form2"> <label for="addr_street">Address<br> <input type="text" name="addr_number" id="Street Number" value="" style="width:50px;display:inline" placeholder="Number" required > <input type="text" name="addr_street" id="Street Name" value="" size="32" placeholder="Street Name" style="display:inline" required /> <span class="field_instructions">Provide the street address that will match the CAD information</span> </label> <label for="occ_name"> Occupancy Name<br> <input type="text" name="occ_name" value="" style="width:100%" placeholder="Occupancy Name"/> <input type="submit" name="button" id="button" value="Submit" class="button green medium"> </form> </div> <div id="rightcol"> <div id="publishingcontrols"> <h2>Publishing Controls</h2> <div align="center"> <a href="#" onclick="document.getElementById('form2').submit();" class="button green large">Save</a> </div> <div id="errors"> <h2>Please fix these first</h2> </div> </div> </div> <script> // adds an effect called "wall" to the validator $.tools.validator.addEffect("wall", function(errors, event) { // get the message wall var wall = $(this.getConf().container).fadeIn(); // remove all existing messages wall.find("p").remove(); // add new ones $.each(errors, function(index, error) { wall.append( "<p><strong>" +error.input.attr("id")+ "</strong> " +error.messages[0]+ "</p>" ); }); // the effect does nothing when all inputs are valid }, function(inputs) { }); // initialize validator with the new effect $("#form2").validator({ effect: 'wall', container: '#errors', // do not validate inputs when they are edited errorInputEvent: null // custom form submission logic }).submit(function(e) { }); </script> </body> </html> 

將其添加到沒有提交按鈕的消防驗證器中:

var $validator= $("#form2").data("validator");
$validator.checkValidity();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM