2013-08-27 30 views
6

如何在jQuery日期選擇器中同時包含語言翻譯和changeMonth和changeYear選項。爲此,我用下面的代碼 用於語言翻譯jquery日期選擇器中的語言翻譯

$(this).datepicker($.datepicker.regional['fr']); 

對於ChangeYear

$(this).datepicker({ 
     changeMonth: true, 
     changeYear: true 
    }); 

我想在一個單一的日期選擇器運行這兩個box.Please幫助

回答

3

查看源區域是選擇一個對象,因此這應該工作:

$(this).datepicker($.extend({}, $.datepicker.regional['fr'], { 
    changeMonth: true, 
    changeYear: true 
})); 
0

這裏有一個簡單的方法(看到這個JFiddle:http://jsfiddle.net/Kp8Nq/)。 你可以改變的,而不是創建一個新的日期選擇器的定位選項:

$(function() { 
    $("#datepicker").datepicker({ 
     changeMonth: true, 
     changeYear: true 
    }); 
    $("#datepicker").datepicker("option", 
     $.datepicker.regional["fr"]); 

    $("#locale").change(function() { 
     $("#datepicker").datepicker("option", 
     $.datepicker.regional[$(this).val()]); 
    }); 
}); 
0

我個人讓用戶決定,如果你有一個多民族的網站:

參見:http://jqueryui.com/datepicker/#localization

<!doctype html> 

<html lang="en"> 
<head> 
    <meta charset="utf-8" /> 
    <title>jQuery UI Datepicker - Localize calendar</title> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <script src="jquery.ui.datepicker-ar.js"></script> 
    <script src="jquery.ui.datepicker-fr.js"></script> 
    <script src="jquery.ui.datepicker-he.js"></script> 
    <script src="jquery.ui.datepicker-zh-TW.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css" /> 
    <script> 
    $(function() { 
    $("#datepicker").datepicker($.datepicker.regional[ "fr" ]); 
    $("#locale").change(function() { 
     $("#datepicker").datepicker("option", 
     $.datepicker.regional[ $(this).val() ]); 
    }); 
    }); 
    </script> 
</head> 
<body> 

<p>Date: <input type="text" id="datepicker" />&nbsp; 
    <select id="locale"> 
    <option value="ar">Arabic (‫(العربية</option> 
    <option value="zh-TW">Chinese Traditional (繁體中文)</option> 
    <option value="">English</option> 
    <option value="fr" selected="selected">French (Français)</option> 
    <option value="he">Hebrew (‫(עברית</option> 
    </select></p> 


</body> 
</html> 
+0

不知道爲什麼[documentation](http://api.jqueryui.com/datepicker/)使用這種語法:'$(selector).datepicker($ .datepicker.regional [「fr」]);'但它didn不爲我工作。上面用'$(「#datepicker」).datepicker(「選項」,...'確實有效。 – resting