Cara menggunakan javascript set value datetime-local

Semua browser utama mendukung jenis atribut. Namun, tidak semua browser utama mendukung semua jenis input yang berbeda dapat bekerja di semua browser utama.

Lihat di bawah untuk setiap jenis masukan dari dukungan browser.


Definisi dan Penggunaan

Atribut type menentukan jenis elemen yang ingin ditampilkan.

Jenis default adalah: text.

Catatan: Atribut ini tidak diperlukan, tapi kami pikir Anda harus selalu menggunakannya.


Perbedaan antara HTML 4.01 dan HTML5

Jenis masukan berikut baru dalam jenis HTML5: warna, tanggal, datetime, datetime-lokal, bulan, minggu, waktu, email, nomor, jangkauan, pencarian, tel dan url.


tatabahasa

Nilai properti

值描述button定义可点击的按钮(通常与 JavaScript 一起使用来启动脚本)。checkbox定义复选框。color New定义拾色器。date New定义 date 控件(包括年、月、日,不包括时间)。datetime New定义 date 和 time 控件(包括年、月、日、时、分、秒、几分之一秒,基于 UTC 时区)。datetime-local New定义 date 和 time 控件(包括年、月、日、时、分、秒、几分之一秒,不带时区)。email New定义用于 e-mail 地址的字段。file定义文件选择字段和 "浏览..." 按钮,供文件上传。hidden定义隐藏输入字段。image定义图像作为提交按钮。month New定义 month 和 year 控件(不带时区)。number New定义用于输入数字的字段。password定义密码字段(字段中的字符会被遮蔽)。radio定义单选按钮。range New定义用于精确值不重要的输入数字的控件(比如 slider 控件)。reset定义重置按钮(重置所有的表单值为默认值)。search New定义用于输入搜索字符串的文本字段。submit定义提交按钮。tel New定义用于输入电话号码的字段。text默认。定义一个单行的文本字段(默认宽度为 20 个字符)。time New定义用于输入时间的控件(不带时区)。url New定义用于输入 URL 的字段。week New定义 week 和 year 控件(不带时区)。

contoh

Input Type: tombol

contoh

Definisi tombol diklik, ketika pengguna mengklik tombol untuk memulai periode JavaScript:


Coba »



Input Type: checkbox

contoh

Kotak memungkinkan pengguna untuk memilih satu atau lebih pilihan di sejumlah pilihan:

我有一辆自行车

我有一辆小轿车

我有一艘船


Coba »



Input Type: warna

contoh

Pilih warna dari pemilih warna:

选择你喜欢的颜色:


Coba »



Jenis Input: tanggal

contoh

Ditetapkan tanggal kontrol:

生日:


Coba »



Input Type: datetime

contoh

Tentukan tanggal dan waktu kontrol (dengan zona waktu):

生日 (日期和时间):


Coba »



Input Type: datetime-lokal

contoh

Tentukan tanggal dan waktu kontrol (tanpa zona waktu):

生日 (日期和时间):


Coba »



Input Type: email

contoh

Bidang Definisi untuk alamat e-mail (bila formulir dikirimkan secara otomatis ke nilai bidang email untuk memverifikasi):

E-mail:


Coba »

Tip: Browser iPhoneSafari akan mengenali jenis masukan url, kemudian mengubah keyboard layar sentuh untuk beradaptasi dengan itu (menambahkan opsi .com).

There are many code snippets available online or on many other blogs and websites but everyone is not able to optimize your blog or website so you need some optimized code snippet. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready to use code and paste it where you want.

See it in a Live Example Below:

Table of Contents

Features:

  1. Light Weight.
  2. Pure Vanilla JavaScript.
  3. Cross Browser.
  4. No External Files.
  5. Fully Customizable.
  6. Single Line Function.

How To Set Value Of Input type=”datetime-local” Via Pure JavaScript?

There are a few easy and understandable steps to achieve your desired functionality using pure Vanilla JavaScript that we are gonna share below. Follow each step perfectly.

Recommended For You:

Most Used HTML DOM Events Attributes For WebDesigners

JavaScript:

setInterval(function(){ 
let today = new Date();
today.setMinutes(today.getMinutes() - today.getTimezoneOffset());
document.getElementById('datePicker').value = today.toISOString().slice(0, -1);
}, 100);
//<input id="datePicker" type="datetime-local" />

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts and problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

❮ Sebelumnya Berikutnya Referensi ❯


Masukan Obyek DatetimeLocal

Input Obyek DatetimeLocal baru di HTML5.

Input objek DatetimeLocal merupakan HTML <input> elemen dengan type = "datetime-lokal".

Catatan: <input> elemen dengan type = "datetime-lokal" tidak menunjukkan sebagai setiap bidang datetime / kalender di Firefox.

Mengakses Masukan DatetimeLocal Object

Anda dapat mengakses <input> elemen dengan type = "datetime-lokal" dengan menggunakan getElementById() :

Contoh

var x = document.getElementById("myLocalDate");

Cobalah sendiri "

Tip: Anda juga dapat mengakses <input type="datetime-local"> dengan mencari melalui unsur-unsur koleksi formulir.

Buat Masukan DatetimeLocal Object

Anda dapat membuat <input> elemen dengan type = "datetime-lokal" dengan menggunakan document. createElement() document. createElement() metode:

Contoh

var x = document.createElement("INPUT");
x.setAttribute("type", "datetime-local");

Cobalah sendiri "

Masukan DatetimeLocal Object Properti

MilikDeskripsiautocompleteSet atau mengembalikan nilai dari autocomplete atribut lapangan datetime lokalautofocusSet atau kembali apakah lapangan datetime lokal harus secara otomatis mendapatkan fokus setelah pemuatan lamandefaultValueSet atau mengembalikan nilai default dari lapangan datetime lokaldisabledSet atau kembali apakah lapangan datetime lokal dinonaktifkan, atau tidakformMengembalikan referensi ke bentuk yang berisi bidang datetime lokallistMengembalikan referensi ke datalist yang berisi bidang datetime lokalmaxSet atau mengembalikan nilai max atribut bidang datetime lokalminSet atau mengembalikan nilai min atribut bidang datetime lokalnameMenetapkan atau mengembalikan nilai dari name atribut lapangan datetime lokalreadOnlySet atau kembali apakah bidang datetime lokal read-only, atau tidakrequiredSet atau kembali apakah bidang datetime lokal harus diisi sebelum mengirimkan formulirstepMenetapkan atau mengembalikan nilai dari step atribut bidang datetime lokaltypePengembalian jenis bentuk elemen bidang datetime lokalvalueMenetapkan atau mengembalikan nilai dari value atribut dari bidang datetime lokal

Masukan DatetimeLocal Object Metode

metodeDeskripsistepDown()Decrements nilai bidang datetime dengan jumlah tertentustepUp()Increment nilai bidang datetime dengan jumlah tertentu

Properti standar dan Acara

Input DatetimeLocal keberatan juga mendukung standar sifat dan peristiwa .


Pages terkait

Tutorial HTML: Bentuk HTML

Referensi HTML: HTML <input> tag

Referensi HTML: HTML <input> jenis atribut


❮ Sebelumnya Berikutnya Referensi ❯