【问题标题】:Javascript is not not working due to unknown reason由于未知原因,Javascript 无法正常工作
【发布时间】:2015-03-25 15:39:30
【问题描述】:

我正在使用自定义 optin 表单。这是代码

<div class="form fix">
    <p class="form-text">Fill This Out and See Your<br>Timeshare Report</p>
    <form name="contactform" action="mail-script.php" method="POST">
        <label for="fname">First Name:
            <input type="text" name="fname" id="fname" />
        </label>
        <br>
        <label for="lname">Last Name:
            <input type="text" name="lname" id="lname" />
        </label>
        <br>
        <label for="email">Email Address:
            <input type="text" name="email" id="email" />
        </label>
        <br>
        <label for="phone">Phone Number:
            <input type="text" name="phone" id="phone" />
        </label>
        <br>
        <label for="phone">Alternate Phone:
            <input type="text" name="phone" id="aphone" />
        </label>
        <br>
        <label for="resort">Resort Name:
            <input type="text" name="resort" id="resort" />
        </label>
        <br>
        <label for="amount">Amount Owed? $:
            <input type="number" name="amount" id="amount" />
            <p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">If Paid Off Leave Zero, Else Put Amount</p>
        </label>
        <br>
        <div class="checkbox">
            <div class="check-text fix">
                <p>I'm Considering To</p>
            </div>
            <div class="check-one fix">
                <input type="checkbox" name="call" id="" value="sell" />Sell It
                <br>
                <input type="checkbox" name="call" id="" value="buy" />Buy It
                <br>
                <input type="checkbox" name="call" id="" value="rent " />Rent It
            </div>
            <div class="check-two fix">
                <input type="checkbox" name="call" id="" value="cancel" />Cancel Mortgage
                <br>
                <input type="checkbox" name="call" id="" value="ownership" />End Ownership
                <br>
                <input type="checkbox" name="call" id="" value="give" />Give It Back
            </div>
        </div>
        <p class="captcha">
            <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg'>
            <br>
            <label for='message'>Enter the code above here :</label>
            <br>
            <input id="6_letters_code" name="6_letters_code" type="text">
            <br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
        </p>
        <input id="submit" type="submit" value="" />
        <p class="submit-text">Ensure all fields are completed and correct, allowing you more benefits, while preventing abuse of our data.</p>
    </form>
</div>
</div>

我想添加一个弹出 javascript 以在有人提交表单时显示成功消息,我正在使用此代码

$('form').on('submit',function(){
    alert('submitted');
});

但由于未知原因,此代码不起作用,这是页面网址 http://timesharesgroup.com/sell/index.html

P.S 我的目标是在用户提交表单时向用户显示成功消息,我认为 javascript 是一种简单的方法,但如果您能想出更好的选择,我将不胜感激 目前表单的工作方式如下:

  1. 用户提交
  2. 为他刷新页面
  3. 我收到一封包含提交数据的电子邮件

**********更新**********************

【问题讨论】:

  • 请添加比“它不起作用”更多的细节。你试图做什么来修复或调试它?你检查过控制台吗?页面中是否包含 jQuery.js?是否正确加载?您的代码是否在 DOMReady 之前运行? alert() 是否显示,但表单仍在提交中?在这里与我们合作...
  • 我在表单下方的 index.html 中添加了代码。请检查更新的问题。
  • 如果我没记错 jquery.js 丢失
  • @Danyal Uncaught ReferenceError: $ is not defined

标签: javascript php jquery html forms


【解决方案1】:

你使用的是jQuery而不是JavaScript。为此,您需要在 head 部分中包含jQuery.js。在&lt;head&gt; 标签中添加以下内容:

&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;

如果你想使用 JavaScript,你可以做如下改动:

原文:&lt;input id="submit" type="submit" value="" /&gt;

修改:&lt;input id="submit" type="submit" onclick="alert("success");" value="" /&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 2015-10-28
    • 2011-11-18
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多