像Bootstrap日期选择器一样,Semantic UI有没有日期选择器? 我搜索了他们的网站,但没有找到。
Jquery日期选择器很好用,但是UI不太适合我的项目。
像Bootstrap日期选择器一样,Semantic UI有没有日期选择器? 我搜索了他们的网站,但没有找到。
Jquery日期选择器很好用,但是UI不太适合我的项目。
看一下这个Semantic UI日历模块,它是由上述拉取请求产生的。有很多自定义选项,而且看起来很不错。
<h3>Input</h3>
<div class="ui calendar" id="example1">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" placeholder="Date/Time">
</div>
</div>
$('#example1').calendar();
我也找了一些相关的内容,但是最好的是语义化UI的日期范围选择器。
在初始化过程中,您可以使用一些自定义类使GUI外观与语义化UI相似:
// Initialize the daterangepicker
$container.find('input').daterangepicker({
buttonClasses: "ui mini button",
applyClass: "positive",
cancelClass: "cancel",
// ...
// ...
// ...
timePicker: true
});
2020年3月2日
,则可以使用以下方式:
语义类:
<!-- Calendar picker -->
<div class="field">
<div class="ui calendar" id="ffa_mar1_cal">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" placeholder="Date">
</div>
</div>
</div>
//custom calendar
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
$('#ffa_mar1_cal').calendar({
type: 'date',
monthFirst: false,
formatter: {
date: function (date, settings) {
if (!date) return '';
var day = date.getDate();
var month = months[date.getMonth()];
var year = date.getFullYear();
return day + '/' + month + '/' + year;
}
}
});
months
是text
的一个参数,可以通过引用settings.text.months
在formatter
对象内访问。月份名称变成var month = settings.text.months[date.getMonth()];
。 - pietrop$(document).ready(function () {
$('.ui.form').form({
fields: {
name: 'minLength[1]',
}
});
$("#_datepicker").datepicker();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<form class="ui form" method="post">
<div class="field">
<label>Date</label>
<input name="date" type="text" placeholder="mm/dd/yyyy" value="" id="_datepicker">
</div>
</form>
这个例子可能看起来不太好,但那是因为我喜欢保持简单的例子。
编辑:如果你需要语义化UI表单验证(我比较喜欢),你将不得不两次重新导入semantic.min.js,或者至少在底部重新导入。
如果你已经没有其他选择了,这个日期选择器可能会有所帮助。我正在使用Semantic UI React来开发我的生产应用程序,在尝试了多个第三方库后,我选择了这个模块作为一个好的日期选择器。在一些CSS覆盖之后,选择器本身看起来和感觉就像其他Semantic UI元素一样。这是我的样子。它可以直接使用,并且与React和Hooks非常容易配合使用。例如,它需要一个名为“customInput”的属性,该属性在日期输入字段的位置呈现任何JSX元素。
const [startDate, setStartDate] = useState(new Date());
const ExampleCustomInput = ({ value, onClick }) => (
<Button basic onClick={onClick}>
{value}
</Button>
);
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
customInput={<ExampleCustomInput />}
/>