![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 徐贊豐 ![]()
![]() |
各位大大 我常常引用DataPicker套件來做成字串框的下拉月曆選單,想請問我能不能將自訂的DatePicker寫成function,隨時可以引用。 我的寫法如下: test1.js function calendar(obj) { var opt = { dayNamesMin: ["日", "一", "二", "三", "四", "五", "六"], monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], prevText: "上月", nextText: "次月", weekHeader: "週", yearRange: "2018:2048", changeMonth: true, changeYear: true, showMonthAfterYear: true, dateFormat: "yy-mm-dd" } $(obj).datepicker(opt); } test1.html <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://code.jquery.com/jquery-3.2.1.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script src="test1.js"></script> <script> var A = $("[name=test]"); calendar(A); </script> <input type="text" name="test" onclick="JavaScript:calendar(this)"> 因為不熟悉,想請教各位大大指點迷津 |