简体   繁体   English

我如何执行两个javascript函数

[英]How can i execute two javascript functions

I am new in HTML, PHP. 我是HTML,PHP的新手。 I have build a page with following coding - 我用以下代码构建了一个页面-

<script src="js/jquery.min.js"></script>
<script src="js/timepicki.js"></script>
<link rel="stylesheet" type="text/css" href="css/timepicki.css">
<script>
$(document).ready(function (){
$(".time_element").timepicki();
});
</script>
<script src="jquery-1.6.2.min.js"></script>
<script src="jquery-ui-1.8.15.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="jqueryCalendar.css">
<script>

   jQuery(function () {
      jQuery( "#datepicker" ).datepicker();
      jQuery( "#datepicker1" ).datepicker();
});
 </script>    

problem is only second one is working. 问题只是第二个正在工作。 If I put the first portion in the place of second it also work but both together does not. 如果我将第一部分替换为第二部分,它也可以工作,但两者都不能。 How can I combine those. 我该如何结合这些。 I tried "body onload" method and also tried "addloadevent" but probably I am not writing the code properly. 我尝试了“ body onload”方法,还尝试了“ addloadevent”,但是可能我编写的代码不正确。 Any help will be greatly appreciated. 任何帮助将不胜感激。

You're including jQuery more than once. 您不止一次包含了jQuery。 Don't do that. 不要那样做 Just include it once, then include your plugins. 只需包含一次,然后包含您的插件。 You can leave your ready blocks separate, or combine them, it's up to you. 您可以将ready模块分开放置,也可以将它们组合在一起,由您决定。

Here's how I would change that: 这是我要更改的方式:

In the head : head

<link rel="stylesheet" type="text/css" href="css/timepicki.css">
<link rel="stylesheet" type="text/css" href="jqueryCalendar.css">

In the body at the very end prior to the closing </body> tag: body在最后之前的闭</body>标记:

<script src="js/jquery.min.js"></script>
<script src="js/timepicki.js"></script>
<script src="jquery-ui-1.8.15.custom.min.js"></script>
<script>
$(".time_element").timepicki();
$("#datepicker, #datepicker1" ).datepicker();
</script>

...where jquery.min.js is a recent version of jQuery, such as v1.11.2. ...其中jquery.min.js是jQuery的最新版本,例如v1.11.2。

Or if you want all the scripts in the head (although that's usually not best practice): 或者,如果您想将所有脚本head (尽管通常这不是最佳实践):

<link rel="stylesheet" type="text/css" href="css/timepicki.css">
<link rel="stylesheet" type="text/css" href="jqueryCalendar.css">
<script src="js/jquery.min.js"></script>
<script src="js/timepicki.js"></script>
<script src="jquery-ui-1.8.15.custom.min.js"></script>
<script>
jQuery(function($) {
  $(".time_element").timepicki();
  $("#datepicker, #datepicker1" ).datepicker();
});
</script>

Other changes I'd probably make: 我可能会进行的其他更改:

  • Give #datepicker and #datepicker1 a common class rather than id s (as with your .time_element ). #datepicker#datepicker1 #datepicker一个公共类,而不是id (与您的.time_element )。

  • Combine the CSS into a single, minified file. 将CSS合并为一个最小的文件。

  • Combine the JS into a single, minified file (or possibly all the JS except for jQuery, and load jQuery from a CDN). 将JS合并为一个最小文件(或除jQuery以外的所有JS,然后从CDN加载jQuery)。

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

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