我有一个动态的文本框列表来捕获一个或多个货币金额。我希望至少一个文本框具有有效的货币金额。
我无法让它完全正常工作。我真的很感激任何想法或建议。
这是我到目前为止...
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/themes/cupertino/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script type="text/ecmascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script type="text/ecmascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/additional-methods.min.js"></script>
<script type="text/javascript" src="js/jquery.maskedinput-1.3.min.js"></script>
<div id="page_wrap"><form action="http://local.host.com/myform/net/send" method="post" accept-charset="utf-8" id="myform">
<h2>Test</h2>
<h3>Enter an amount and click send</h3>
<?php //foreach ($recs as $rec): ?>
<Fieldset>
<label for="Amount_1">Amount</label>
<input name="Amount_1" type="text" id="Amount_1" />
</Fieldset>
<Fieldset>
<label for="Amount_2">Amount</label>
<input name="Amount_2" type="text" id="Amount_2" />
</Fieldset>
<Fieldset>
<label for="Amount_3">Amount</label>
<input name="Amount_3" type="text" id="Amount_3" />
</Fieldset>
<?php // endforeach; ?>
<span class="button right"><input type="submit" value="Send" /></span>
<br class="flt_clear" />
</form>
<script>
$(document).ready(function() {
$('input[name^="Amount_"]').mask("$?999");
$.validator.addMethod("pickAtLeastOne", function(value, element, param) {
return $('input[name^="Amount_"]').val() == "$";
});
$('#myform').validate();
$('input[name^="Amount_"]').each(function() {
$(this).rules("add", {
pickAtLeastOne: true,
messages: {
pickAtLeastOne: "Please enter at least one amount"
}
});
});
});
</script>
</body>
</html>