[英]What is the easiest way to find out character repetition in a string using JS?
[英]what is the easiest/best way to validate a form using js?
目的:
我希望用戶在表單上輸入信息,然后我將使用該信息生成不同的結果。
繼承我的代碼:
http://jsfiddle.net/5HUVm/
<form id="form1" name="form1" method="post">
<table>
<tr>
<td>I am interested in:</td>
<td><input type="radio" name="choice" value="consume" id="consume"/> Cosuming and/or distributing OTC Markets data
</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="choice" value="extranet" id="extranet"/> Providing connectivity to OTC Markets(Extranet)</td>
</tr>
<tr>
<td>Data products:</td>
<td><input type="checkbox" name="realtime" value="realtime" id="realTime">Real-time data</td>
<td><input type="checkbox" name="otcdata" value="otcdata" id="compData">OTC Company Data</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="eodprice" value="eodprice" id="eod">End of Day Pricing Data</td>
<td><input type="checkbox" name="otccompliance" value="otccompliance" id="otcComp">OTC Compliance Data</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="otcsecurity" value="otcsecurity" id="otcSec">OTC Security Data</td>
<td><input type="checkbox" name="otcqhistory" value="otchistory" id="otcHist">OTC Quote History</td>
</tr>
<tr>
<td>Data use:</td>
<td>
<select name="products" id="prod">
<option value="select">Select</option>
<option value="personal">Personal Use Only</option>
<option value="distEx">Distribute Externally Only</option>
<option value="distIn">Distribute Internally Only</option>
<option value="distBoth">Distribute Externally & Internally Only</option>
</select>
</td>
</tr>
<tr>
<td>Firm type:</td>
<td>
<select name="firm" id="firm">
<option value="select">Select</option>
<option value="broker">Broker-dealer</option>
<option value="oms">Order Management System</option>
<option value="finanInfo">Financial Information Service/Portal</option>
<option value="service">Service Bureau</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="reset" id="re">
<input type="button" id="sub" value="Submit" onclick="valid(this)">
</td>
</tr>
</table>
</form>
所以你可以看到有復選框,單選按鈕,下拉菜單。
驗證已檢查/選擇的內容的最佳方法是什么?
我剛在想:
許多if語句然后使用變量為不同的選擇存儲特殊的“數字”然后taht數字將用於生成結果頁面
例如:
用戶選擇消費,實時數據和結束日數據,可以說選擇1用戶點擊提交,結果頁面將顯示特殊鏈接/文章。
最簡單的方法是使用已編寫的某種形式的插件,但允許您自定義:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
有很多驗證腳本可以完成你想要做的事情 - 不要重新發明輪子....去抓一個並使用它:
原型: http : //tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
JQuery: http : //bassistance.de/jquery-plugins/jquery-plugin-validation/
YUI: http : //www.yuiblog.com/blog/2009/12/03/yui-3-gallery-form-module/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.