如何从js文件中的html文件中调用jquery函数

时间:2019-08-30 11:19:49

标签: javascript php jquery html ajax

我不知道如何从HTML文件中调用jQuery函数。

此功能始于HTML文件中。我将其移到JS文件中,并希望以此命名它,因为当我使用不同语言的文件时,代码看起来更加简洁。

$(function() {
  $('#datepicker').datepicker({
    format: "dd/mm/yyyy",
    autoclose: true,
    todayHighlight: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    autoclose: true,
    changeMonth: true,
    changeYear: true,
    orientation: "button"
  });
});

$(function() {
  $('#datepicker2').datepicker({
    format: "dd/mm/yyyy",
    autoclose: true,
    todayHighlight: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    autoclose: true,
    changeMonth: true,
    changeYear: true,
    orientation: "button"
  });
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.css" rel="stylesheet" id="bootstrap-css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="calendar.js"></script>
<div onclick="datumEins()" class="container">
  <div class="row">
    <h2>Startdatum</h2>
  </div>
  <div class="row">
    <div class='col-sm-6'>
      <form>
        <div class="form-group">
          <div class='input-group date' id='datepicker'>

            > i think the calling must be putted in the input tag

            <input type='text' id="datum1" class="form-control" />
            <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<!--ENDDATUM-->
<div onclick="datumZwei" class="container">
  <div class="row">
    <h2>Enddatum</h2>
  </div>
  <div class="row">
    <div class='col-sm-6'>
      <form>
        <div class="form-group">
          <div class='input-group date' id='datepicker2'>

            > i think the calling must be putted in the input tag

            <input type='text' id="datum2" class="form-control" />
            <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
            </span>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>

0 个答案:

没有答案