javascript jquery datepicker 在 IE7 和 IE8 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4745073/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery datepicker not working in IE7 and IE8
提问by Richard Knop
This is my js:
这是我的js:
$(document).ready(function() {
 $("input#dateTill").datepicker();
});
My HTML:
我的 HTML:
<input type="text" name="dateTill" id="dateTill" class="input" value="20.1.2011" maxlength="10" size="10" style="margin-left: 0; background: url(images/icons/16_calendar.png) 75px center no-repeat;" />
The datepicker does work in all normal browsers like Firefox, Chrome, Opera. It does not work in IE7 and IE8.
日期选择器可以在所有普通浏览器中工作,例如 Firefox、Chrome、Opera。它不适用于 IE7 和 IE8。
When I click inside the input field, the datepicker window does not appear.
当我在输入字段内单击时,日期选择器窗口不会出现。
Any ideas? I am using jquery 1.4.4.
有任何想法吗?我正在使用 jquery 1.4.4。
回答by crowicked
First of all, just to be sure, don't use the same string for the id and the name property. And for God's sake, don't define your class with a reserved word like input, it's and internal class/element already. Go for something like pickerClass. Also, I think your jQuery selector syntax is wrong, no need for the inputpart, you already have an id for that element. This:
首先,为了确定,不要对 id 和 name 属性使用相同的字符串。看在上帝的份上,不要用像input这样的保留字来定义你的类,它已经是内部类/元素了。选择像pickerClass这样的东西。另外,我认为您的 jQuery 选择器语法是错误的,不需要输入部分,您已经有了该元素的 id。这:
$("#dateTill").datepicker();
OR
或者
$("input.pickerClass").datepicker();
if for some strange reason you want to select multiple inputs at once. Also, if you have a CSS defined class already then move the inline styling into the CSS if it's gonna be used for more input fields.
如果出于某种奇怪的原因您想一次选择多个输入。此外,如果您已经有一个 CSS 定义的类,那么如果要用于更多输入字段,请将内联样式移动到 CSS 中。

