gpt4 book ai didi

javascript - 通过 jQuery 提交表单时 Required 不起作用?

转载 作者:搜寻专家 更新时间:2023-10-31 08:24:54 25 4
gpt4 key购买 nike

情况

我有一个包含所需输入的表单。它曾经有效,但自从我使用 JavaScript/jQuery 提交表单后,不再需要必填字段。

问题

在使用 JavaScript/jQuery 提交表单时,如何使输入字段成为必填项?

HTML

<fieldset>
<div class="form-group form-group-sm">
<label class="col-md-3 control-label">Name:</label>
<div class="col-md-6">
<input required name="ttlAddCategory" id="frmAddCategoryTtl" placeholder="" class="form-control input-md col-md-6" type="text" value="">
</div>
</div>
<div class="form-group form-group-sm">
<label class="col-md-3 control-label">Icon:</label>
<div class="col-md-6">
<input name="iconAddCategory" id="frmAddCategoryIcon" placeholder="Upload uw Marker en plaats hier uw URL. Max. 70x70 Aangeraden 33x44" class="form-control input-md col-md-6" type="text" >
</div>
</div>
<div class="form-group form-group-sm">
<label class="col-md-3 control-label">&nbsp;</label>
<div class="col-md-3">
<input type="button" class="btn btn-primary" value="Toevoegen" id="btnAddCategory">
</div>
<div class="col-md-4">
<a id="cke_29" class="btn btn-primary" title="Afbeelding" tabindex="-1" role="button" aria-labelledby="cke_29_label" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(23,event);" onfocus="return CKEDITOR.tools.callFunction(24,event);" onclick="CKEDITOR.tools.callFunction(25,this);return false;">
Upload hier
</a>
</div>
</div>
</fieldset>

JS

    $('#btnAddCategory').click(function() {
if ($('#frmAddMarkerCat').find('input[name="iconAddCategory"]').val() == '') {
$('#frmAddMarkerCat').find('input[name="iconAddCategory"]').val('default');
}

$('#frmAddMarkerCat').submit();

});

最佳答案

如果手动提交表单可以解决问题,那么与其在表单对象上执行 .submit() 尝试通过触发您用于手动提交的按钮上的点击来复制手动操作.

代替:

$('#formID').submit();

尝试:

$('#submitButton').trigger('click');

关于javascript - 通过 jQuery 提交表单时 Required 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com