[Javascript] Nhập ngày tháng năm sinh xuất tuổi
Sun May 20, 2018 4:35 pm
- Code:
//Khi Field ngaysinh onChange()
function myFunction() {
//Lấy dữ liệu thời gian hiện tại
var getYearCurrent = new Date().getFullYear();
var getMonthCurrent = new Date().getMonth();
var getDateCurrent = new Date().getDate();
//Lấy dữ liệu thời gian ngày sinh
var getYearBirth = window.parent.Xrm.Page.getAttribute("ngaysinh").getValue().getFullYear();
var getMonthBirth = window.parent.Xrm.Page.getAttribute("ngaysinh").getValue().getMonth();
var getDateBirth = window.parent.Xrm.Page.getAttribute("ngaysinh").getValue().getDate();
//Tính tuổi
var Age = getYearCurrent - getYearBirth;
if (getMonthCurrent > getMonthBirth)
{
Age = Age + 1;
}
else if (getMonthCurrent == getMonthBirth)
{
if (getDateCurrent >= getDateBirth)
{
Age = Age + 1;
}
}
Age = Age - 1;
window.parent.Xrm.Page.getAttribute("tuoi").setValue(Age);
}
//Khi Form onLoad()
function blockAge() {
window.parent.Xrm.Page.getControl("tuoi").setDisabled(true);
}
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|