https://developer.mozilla.org/vi/docs/Glossary/Truthy
https://developer.mozilla.org/vi/docs/Glossary/Falsy
http://www.sitepoint.com/javascript-truthy-falsy/
Hiển thị các bài đăng có nhãn javascript. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn javascript. Hiển thị tất cả bài đăng
Thứ Sáu, 11 tháng 3, 2016
Thứ Hai, 22 tháng 2, 2016
Đoạn code Format Number ( ngắt theo ngàn, triệu ... ) bằng Javascript
Viết lại từ phiên bản C# và xử lý thêm trường hợp số âm
http://www.hanhtranglaptrinh.com/2011/12/oan-code-format-number-ngat-theo-ngan.html
http://www.hanhtranglaptrinh.com/2011/12/oan-code-format-number-ngat-theo-ngan.html
var insertAt = function (originalStr, index, string) { return originalStr.substr(0, index) + string + originalStr.substr(index); } var formatNumber = function (number) { var rs; var part = number.replace("-", "").split('.'); var len = part[0].length; var i = parseInt(len / 3); if (i > 0) { var pos = len % 3; if (pos > 0) { part[0] = insertAt(part[0],pos, ","); pos += 4; } else { pos = 3; } for (var k = 1; k < i; k++) { part[0] = insertAt(part[0],pos, ","); pos += 4; } } if (number.indexOf(".") >= 0) { rs = part[0] + "." + part[1]; } else rs = part[0]; if (number.indexOf("-") == 0) rs = "-" + rs; return rs; }
Chủ Nhật, 29 tháng 7, 2012
Sử dụng Clipboard bằng javascript
Để đưa 1 giá trị text vào clipboard:
Để lấy giá trị text đang lưu trong clipboard:
Tuy nhiên để các hàm này hoạt động thì trình duyệt người dùng phải cho phép sử dụng clipboard. Hiện giờ đa số các trình duyệt đã disable tính năng này vì lý do an ninh hay 1 vài vấn đề khác:
- window.clipboardData.setData('Text','aaaaaaaa');
- var value = window.clipboardData.getData("Text");
Problems caused by unintended clipboard access
There are several types of problems which can happen if a website is able to use your system's clipboard through javascript:- A website may erase the clipboard data, which may cause you to lose important data that you had copied previously into the clipboard.
- A website may change the clipboard data, which may cause different data to be pasted later on instead of the data you intended to paste originally.
- A website may read the clipboard data, and use them in malicious ways or send them to a third party without your knowledge.
Thứ Hai, 18 tháng 6, 2012
Check All và UnCheck All CheckBoxList ASP.NET
Có thể xử lý check all hoặc uncheck all bên phía server hoặc client nhưng mình thích sử dụng javascript trên client hơn vì không phải postback lên server. Đặc biệt nữa là sử dụng javascript thì không phụ thuộc vào công nghệ nào cả, có thể sử dụng cho nhiều công nghệ làm web khác nhau.
Hàm js sử dụng để check all hoặc uncheck all các item trong control CheckBoxList ASP.NET
Sử dụng:
Hàm js sử dụng để check all hoặc uncheck all các item trong control CheckBoxList ASP.NET
- <script language="javascript" type="text/javascript">
- function SetAllStateCheckBoxList(chkID, state) {
- var chk = document.getElementById(chkID);
- var items = chk.getElementsByTagName("input");
- for (var i = 0; i < items.length; i++) {
- items[i].checked = state;
- }
- }
- </script>
- <input type="button" value="chọn hết" onclick="SetAllStateCheckBoxList('<%=CheckBoxList1.ClientID %>',true)" />
- <input type="button" value="bỏ chọn hết" onclick="SetAllStateCheckBoxList('<%=CheckBoxList1.ClientID %>',false)" />
- <asp:CheckBoxList ID="CheckBoxList1" runat="server">
- </asp:CheckBoxList>
Chủ Nhật, 10 tháng 6, 2012
Sử dụng Cookie bằng javascript
Hôm nay mình làm chức năng đăng nhập bằng javascript, cần sử dụng cookie để lưu trữ thông tin đăng nhập cho phần nhớ mật khẩu. Đây là đoạn code javascript để sử dụng cookie mình tham khảo trên w3schools:
Xem thêm Sử dụng Cookie trong ASP.NET
- function getCookie(c_name) {
- var i, x, y, ARRcookies = document.cookie.split(";");
- for (i = 0; i < ARRcookies.length; i++) {
- x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
- y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
- x = x.replace(/^\s+|\s+$/g, "");
- if (x == c_name) {
- return unescape(y);
- }
- }
- }
- function setCookie(c_name, value, exdays) {
- var exdate = new Date();
- exdate.setDate(exdate.getDate() + exdays);
- var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
- document.cookie = c_name + "=" + c_value;
- }
Đăng ký:
Bài đăng
(
Atom
)