简体   繁体   English

jQuery 日期选择器在 IE 中不起作用

[英]jQuery Date Picker Not Working In IE

I'm trying to get the jQuery UI Date Picker to work in IE via php.我正在尝试通过 php 使 jQuery UI 日期选择器在 IE 中工作。 I did their basic example with a div and it works even in IE.我用 div 做了他们的基本示例,它甚至在 IE 中也能工作。 However trying to work it into my code works on Chrome and Firefox, but not IE.但是,尝试将其添加到我的代码中适用于 Chrome 和 Firefox,但不适用于 IE。 Running IE 11. Here is just the heart of the part that is doing the date picker:运行 IE 11。这是执行日期选择器部分的核心:

echo"   <link rel=\"stylesheet\" href=\"//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css\"> \n";
echo " <script src=\"https://code.jquery.com/jquery-1.12.4.js\"></script>";
echo " <script src=\"https://code.jquery.com/ui/1.12.1/jquery-ui.js\"></script>";
echo " <script>";
echo " $( function() {";
echo " $( \"#datepicker\" ).datepicker();";
echo " } ); ";


echo " $( function() {";
echo " $( \"#datepicker1\" ).datepicker();";
echo " } ); ";
echo " </script> ";


echo "<tr>                                                          \n";
    echo "<td>                                                                      \n";
        echo " <form action=\"Web.php\" method=\"post\">                            \n";
        if(!empty($_POST["datefrom"]))
            $datefr = $_POST['datefrom'];
        echo "  <b>Date From: (ex: 7/12/2017):</b> <input type=\"text\" id=\"datepicker\" name=\"datefrom\" value=\"$datefr\" >\n";
    echo "</td>                                                                     \n";
    echo "<td>                                                                      \n";
        if(!empty($_POST["dateto"]))
            $dateto = $_POST['dateto'];
        echo "  <b>Date To:   (ex: 7/12/2017):</b> <input type=\"text\" id=\"datepicker1\" name=\"dateto\" value=\"$dateto\" >\n";
    echo "</td>                                                                     \n";
    echo "<td>                                                                      \n";
    echo "</td>                                                                     \n";
echo "</tr>                                                                         \n";

It works great in Chrome and Firefox.它在 Chrome 和 Firefox 中运行良好。 But in IE all I have is the field to type in the date with no date picker.但在 IE 中,我所拥有的只是输入日期的字段,而没有日期选择器。 I used the example:我用的例子:

Datepicker jQuery UI日期选择器 jQuery UI

I'm not sure if IE isn't liking something specific.我不确定 IE 是否不喜欢特定的东西。 I do have some styling on the table.我的桌子上确实有一些样式。 My next thing to try was going to be commenting out all the styling and see if it shows up after that.我接下来要尝试的是将所有样式注释掉,然后看看它是否会出现。

Was hoping someone spots it right off.希望有人马上发现它。

I was able to do an inspect and found this error - "SCRIPT5007: The value of the property '$' is null or undefined, not a Function object" which points to:我能够进行检查并发现此错误 - “SCRIPT5007:属性‘$’的值为空或未定义,不是函数对象”,它指向:

  $( function() { $( "#datepicker" ).datepicker(); } );

I can't post all the rendered HTML as I would have to sanitize a bunch of it.我无法发布所有呈现的 HTML,因为我必须清理其中的一堆。 Here is the part for the jQuery UI and the datepicker sections这是 jQuery UI 和 datepicker 部分的部分

  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css"> 
 <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 <script> 
    $( function() { $( "#datepicker" ).datepicker(); } );  $( function() { $( "#datepicker1" ).datepicker(); } ); 
 </script>

 <td>                                                                       
 <form action="Web.php" method="post">          
    <b>Date From: (ex: 7/12/2017):</b> <input type="text" id="datepicker" name="datefrom" value="" >
</td>                                                                       
<td>                                                                        
    <b>Date To:   (ex: 7/12/2017):</b> <input type="text" id="datepicker1" name="dateto" value="" >
</td>                                                                       

Please update your post with a console log or error report for what's going on when you are using IE. 请使用控制台日志或错误报告更新您的帖子,以了解使用IE时的情况。 I can use IE on Windows 10 and load datepicker() just fine for jQuery UI. 我可以在Windows 10上使用IE并为jQuery UI加载datepicker()。 It's one giant perk of jQuery - it works on a lot of browsers. 这是jQuery的一大优势-它适用于许多浏览器。 That said, older versions of IE might not work with it. 也就是说,较旧版本的IE可能无法使用。 For one, you can use type="date" for modern browsers, and revert to old school core JS for a date box pop up. 例如,您可以将type =“ date”用于现代浏览器,然后还原到旧式的JS核心,弹出一个日期框。 Or, use a polyfill. 或者,使用polyfill。 At the very least though, unless you are using an extremely old version of IE then this code should work fine... It works on my IE at least. 不过至少,除非您使用的是IE的极旧版本,否则此代码应该可以正常工作……至少在我的IE上有效。

<!-- SCRIPT SRC INCLUDES HERE --> 

<input type="text" id="anythingYouWantHere" class="customDatepickerClass">
<input type="text" id="anythingYouWantHere2" class="customDatepickerClass">
<input type="date" id="defaultHTML5">

<script>
 $(document).on('ready', function(){
  $(".customDatepickerClass").datepicker(); // initialize all datepickers at once
 }); 
</script>

It was a software issue in our company. 这是我们公司的软件问题。 They were trying out some software to monitor what sites we go to and it took it a while before it hit all the browsers. 他们正在尝试一些软件来监视我们访问的网站,并且花了一段时间才使它进入所有浏览器。 First IE. 第一个IE。 I think it was blocking the loading of the jQuery script items. 我认为这阻止了jQuery脚本项的加载。 Anyway it's working now on all browser. 无论如何,它现在可以在所有浏览器上使用。 Gotta love this stuff. 一定喜欢这个东西。 Thanks for all the help. 感谢您的所有帮助。

In JS you have to wrap it into a Timeout Function:在 JS 中,你必须把它包装成一个超时函数:

setTimeout(function() { ... ... }, 600); setTimeout(function() { ... ... }, 600);

This is necessary in many cases when you want to tweak the DOM using jQuery after page loading.在许多情况下,当您想在页面加载后使用 jQuery 调整 DOM 时,这是必要的。 The page has to be fully loaded, otherwise you won't be able to use jQuery selectors on the not yet existing DOM tree.该页面必须完全加载,否则您将无法在尚不存在的 DOM 树上使用 jQuery 选择器。 They will report back 'empty' and your code cannot be executed upon them.他们将报告“空”并且您的代码无法在他们身上执行。

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

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