我有一个表单,人们可以点击并添加字段到表单,我需要让它验证这些字段中的值,如果它被点击。Javascript验证
所以说我点击它两次,并获得2个独立的字段集,我需要旋转%,以确保它在保存时等于100。
我已经把这个函数放在保存中进行验证,除非编辑了一个不包含任何字段的不同表单。
我想看看最简单的方法是检查并看看字段是否在那里,所以我可以检查它们。
这里是我的代码:
function audit()
{
var totalsum = 100;
$('[name="rotation\\[\\]"]').each(
function()
{
totalsum -= ($(this).val() * 1);
}
)
if(totalsum > 0){
alert("Your rotation % does not equal 100");
return false;}
return true;}
$('.add_creative img').click(
function(){
$.post('/json/ad_creative/',
{ action: "add_creative", this_brand_id: $("[name='this_brand_id']").val(), adtype: $('.new_run [name="adtype"]').val()},
function(data){
if(data.result){
$('.add_creative').append(data.html)
}
},
'json'
)
只会部分工作,因为迈克不仅需要验证字段的存在或内容,但如果他们的总和是100. – memical