2013-08-27 26 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