jquery - 必填字段在 Select2 选择框中不起作用
问题描述
我正在使用 Select2 来自定义选择框。选择框是必填字段。但是,它没有按预期工作。我可以知道为什么会这样吗?谢谢。
$(document).ready(function() {
$('.js-example-basic-single').select2({
dropdownAutoWidth: true,
dropdownParent: $('#parent')
});
});
<!DOCTYPE html>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<form enctype="multipart/form-data" id="testForm" method="post" name="testForm" action="#">
<table width="200">
<tr>
<td width="35" />
<td class="label" width="160"> Authorized By:</td>
<td>
<div id='parent'>
<select class="js-example-basic-single" name="friend" style="width:60%" required>
<option />
<option value="John">John</option>
<option value="Kate">Kate</option>
<option value="Zoe">Zoe</option>
<option value="Peter">Peter</option>
</select>
</div>
</tr>
<tr>
<td align="center" colspan="3" height="35"><button class="button" type="submit">Submit</button></td>
</tr>
</table>
</form>
</HEAD>
</HTML>
解决方案
推荐阅读
- r - 错误替换有 1 行,r 闪亮应用中的数据有 0
- mahapps.metro - MetroApps 未找到 ResourceDictionary 2.0.0-alpha0748
- reactjs - React 测试库的 waitFor() 返回 null
- c# - 如何处理在 C# 中加载时显示为串联字符串的 Crystal Report 记录选择公式?
- reactjs - 父元素的排队 React 更新是否也总是更新子元素?
- python - 使用 .loc 覆盖值
- angular - 使用变量 angular2 路由?
- python - 如何规范化 [0,1] 范围内的数据框中的数据?
- c# - MailKit 的 IMessageSummary.Envelope.InReplyTo 字段始终为空
- python - 使用 lxml 添加具有不同于根元素的命名空间的 xml 子元素