简体   繁体   English

带有IE条件注释的动态javascript吗?

[英]Dynamic javascript with IE's conditional comments?

I've got a legacy web app that I'm trying to modify a bit. 我有一个旧的Web应用程序,正在尝试进行一些修改。 I've added a jQueryUI datetime picker ( http://trentrichardson.com/examples/timepicker/ ) to several pages (tied to a text input) so the user can select start/end date/times. 我已经将jQueryUI日期时间选择器( http://trentrichardson.com/examples/timepicker/ )添加到了多个页面(与文本输入绑定),以便用户可以选择开始/结束日期/时间。 I have it configured to use 'select' boxes instead of 'sliders' for the hour/minute selection. 我将其配置为使用“选择”框而不是“滑块”进行小时/分钟选择。 This works fine in all the browsers I've tested it with except for IE8 (haven't tested in earlier versions of IE). 在我测试过的所有浏览器中,此效果都很好,除了IE8(尚未在IE的早期版本中测试过)。 In IE8, it's very slow to respond to date selections. 在IE8中,响应日期选择非常慢。 Here's the javascript code that creates the datetime picker: 这是创建日期时间选择器的javascript代码:

$("#dtpStart").datetimepicker({
  controlType: "select",
  timeFormat: "HH:mm",
  stepMinute: 15
});

If I remove the controlType: "select", line, the widget defaults to using sliders, and doing that speeds up it's usage in IE8. 如果我删除controlType: "select",行),则该小部件默认使用滑块,这样可以加快它在IE8中的使用。 So I'd like to be able to only include that line if the user is using IE > 8. That way, IE8 and earlier would get sliders while IE9+ and non-IE browsers would get the select boxes. 因此,我希望仅在用户使用IE> 8时才包含该行。这样,IE8和更早版本将获得滑块,而IE9 +和非IE浏览器将获得选择框。

I thought I might be able to do that by using IE's conditional comments but I can't get it to work. 我以为我可以通过使用IE的条件注释来做到这一点,但我无法使其正常工作。 I've never used them before though and might not be doing it right. 我以前从未使用过它们,并且可能做得不好。 I've tried variations of: 我尝试了以下方法的变体:

$("#dtpStart").datetimepicker({
  <!--[if ! IE]><!-->    controlType: "select",<!--<![endif]-->
  timeFormat: "HH:mm",
  stepMinute: 15
});

with no success; 没有成功; I still end up with sliders no matter what browser I'm using. 无论使用哪种浏览器,我仍然会遇到滑块问题。 I'm guessing that's because I'm in the middle of defining the datetimepicker when I'm trying to use the conditional comments? 我猜是因为我在尝试使用条件注释时正在定义datetimepicker?

Any suggestions on a way to do this? 有什么建议可以做到这一点吗?

You can try Conditional Compilation : 您可以尝试Conditional Compilation

var datetimePickerObject = {
  controlType: "select",
  timeFormat: "HH:mm",
  stepMinute: 15
};
/*@cc_on
delete datetimePickerObject.controlType;
@*/
$("#dtpStart").datetimepicker(datetimePickerObject);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM