javascript - 日期选择器未定义 - jQuery

标签 javascript jquery python django datepicker

我创建了一个 Django 应用程序。在我的应用程序中,我有一个注册,其中有一个日期字段。为此,我使用 jQuery datepicker。它以前工作正常,但今天当我开始我的应用程序时,由于某种未知的原因它无法工作。我无法理解为什么它在我的代码中不起作用,但是当我在新的 html 中单独给出该脚本时工作正常。现在显示的错误是 datepicker 不是函数。有人可以研究一下吗?我将在此处粘贴我的 html 代码。

html

<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script>
    $(function() {
        $( "#datepicker" ).datepicker({
            changeMonth: true,
            changeYear: true
        });
    });
</script>

</head>
<title>Login/Registration Page</title>
<script type="text/javascript">

   //Created / Generates the captcha function    
    function DrawCaptcha()
    {
        var a = Math.ceil(Math.random() * 10)+ '';
        var b = Math.ceil(Math.random() * 10)+ '';       
        var c = Math.ceil(Math.random() * 10)+ '';  
        var d = Math.ceil(Math.random() * 10)+ '';  
        var e = Math.ceil(Math.random() * 10)+ '';  
        var f = Math.ceil(Math.random() * 10)+ '';  
        var g = Math.ceil(Math.random() * 10)+ '';  
        var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
        document.getElementById("txtCaptcha").value = code
    }

    // Validate the Entered input aganist the generated security code function   
    function ValidCaptcha(){
        var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2) return true;        
        return false;

    }

    // Remove the spaces from the entered and generated code
    function removeSpaces(string)
    {
        return string.split(' ').join('');
    }

    </script>
<body bgcolor="#736F6E" onLoad="DrawCaptcha();">
<div align="center">
<form name="userInputForm" method="POST" id="myFormid" action="http://10.1.0.90:8080/login/">
  <div style="float:left;width:100%;">
    <p style="float:left;margin-right:10px;width:auto;">
      <label style="float:left;">Email id</label>
      <br/>
      <input type="text" name="username" size="25" />
    </p>
    <p style="float:left;margin-right:10px;width:auto;">
      <label style="float:left;">Password</label>
      <br/>
      <input type="password" name="password" size="25" />
      {% if invalid %}
      Mismatch in your email/password. 
      {% endif %} </p>
  </div>

  <p style="clear:both;float:left;">
    <input type="submit" value="Log in" style="float:left;margin-right:4px;"/>&nbsp;


{% load facebookconnect %}
{% facebook_connect_login_button %}
{% facebook_connect_script %}


    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a HREF="http://10.1.0.90:8080/forgotPassword/">Forgotten your password?</a></p>
  </div>
</form>
<br>
<script type="text/javascript">
function userCheck(){
    /*document.getElementById('myFormid').action = "http://10.1.0.90:8080/login/";
    if ((document.userInputForm.username.value.length==0)) */
}
</script>
<form name ="myform"  method="POST" id='FormID'>
<table>
  <tr>
    <td>First name</td>
    <td><input type="text" name="firstName" value=""  maxlength="100" />
      <b id="firstNameID" style="font-family:Times New Roman;color:#B4045F;font-size:14px;"> </td>
  </tr>
  <tr>
    <td>Last name</td>
    <td><input type="text" name="lastName" value="" maxlength="100" />
    </td>
  </tr>
  <tr>
    <td>E-mail</td>
    <td><input type="text" name="email" value="" maxlength="100" />
    </td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input type="password" name="password" value="" maxlength="100"  />
      <b id="passwordID" style="font-family:Times New Roman;color:#B4045F;font-size:14px;"> </td>
  </tr>
  <tr>
    <td>Re-Type Password</td>
    <td><input type="password" name="password1" value="" maxlength="100"  />
      <b id="passwordID1" style="font-family:Times New Roman;color:#B4045F;font-size:14px;"> </td>
  </tr>
  <tr>
    <td>Gender:</td>
    <td><input type="radio" name="sex" value="male" />
      Male
      <input type="radio" name="sex" value="female" />
      Female </td>
  </tr>
  <tr>
    <td>Birthday</td>
    <td><input type="text" name="birthday" id="datepicker" value="" maxlength="100" />
    </td>
  </tr>
  <tr>

  <td width="150">Captcha</td>
    <td><input type="text" id="txtCaptcha" 
            style="background-image:url(1.jpg); text-align:center; border:1px;
            font-weight:bold; font-family:Modern" />
      <input type="button" id="btnrefresh" value="Refresh" onClick="DrawCaptcha();" />
    </td>
    </tr>
    <tr>
        <td>Enter above text</td>
        <td style="float:left;"><input type="text" id="txtInput" value="" maxlength="100" />
      <b id="textcaptcha" style="font-family:Times New Roman;color:#B4045F;font-size:14px;"> </td>
    </tr>
</table>
</form>
<div style="width:200; float:left; margin:20px 0 0 155px;">
  <input type="button" value="Sign Up" onClick="isEmpty();"/>
</div>
<script type="text/javascript">
function isEmpty(){
    if  ((document.myform.firstName.value.length==0)) 
        {
        document.getElementById('firstNameID').innerHTML = 'Please fill this field';
        return true;
        }
    else if ((document.myform.password.value.length==0)) 
        {
        document.getElementById('passwordID').innerHTML = 'Please fill this field';
        return true;
        }
    else if (document.myform.password.value != document.myform.password1.value)
        {
        document.getElementById('passwordID1').innerHTML = 'Password mismatch';
        return true;
        }
    else if (! ValidCaptcha())
        {
            document.getElementById('textcaptcha').innerHTML = 'Please fill the captcha correctly';
        }

    else 
        { 
        document.getElementById('FormID').action = "http://10.1.0.90:8080/registrationForm/";
        document.getElementById('FormID').submit();
        return false; 
        }
}
</script><br><br>

</body>
</html>

最佳答案

我不知道这是否与您的问题有关,但您发布的代码片段中有一些无效的 HTML。我首先要确保所有标签都是平衡的,你有一个不会关闭的第二种表单标签。此外,您的表格中有几个粗体标签也未关闭。

关于javascript - 日期选择器未定义 - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5616570/

相关文章:

javascript - 为什么 Swagger 规范不提供 OAuth2 身份验证的 clientId?

javascript - 原型(prototype) js super 方法调用或类似的东西

javascript - 条形图上的 jqplot 工具提示

python - 如何编写单元测试来查看属性是否设置为indexed=False?

python - 多索引在表格右侧打印二级索引标签

javascript - 等待 useEffect 完成,然后访问对象属性

javascript - 在 Angular 2 中以编程方式加载和卸载模块

javascript - 如何使用 jQuery 保存 JavaScript 变量并将它们传递到下一个页面?

javascript - div contenteditable,XSS

python - Cartopy-Python 语法 - 一行中多个对象/国家