网址自动填充到页面上的一个框中

时间:2017-02-06 16:08:22

标签: javascript html

如何将用户当前自动填充的页面的网址设置为页面上的方框?

在我的网站404页面上,我们有一个表格供用户填写姓名,电子邮件等。我希望其中一个表格框能够自动填充用户当前所在的页面。

以下是我目前的代码:



    <form id="contactForm" class="scaffold-form" action="https://mpex.com/contacts/index/post/" method="post">
        <div class="fieldset">
        <h2 class="legend">Contact Information</h2>
        <p class="required">* Required Fields</p>
        <ul class="form-list">
        <li class="fields">
        <div class="field"><label class="required" for="name"><em>*</em>Name</label>
        <div class="input-box"><input id="name" class="input-text required-entry" title="Name" type="text" value="" name="name" /></div>
        </div>
        <div class="field"><label class="required" for="email"><em>*</em>Email</label>
        <div class="input-box"><input id="email" class="input-text required-entry validate-email" spellcheck="false" title="Email" type="email" value="" name="email" /></div>
        </div>
        </li>
        <li><label for="telephone">Telephone</label>
        <div class="input-box"><input id="telephone" class="input-text" title="Telephone" type="tel" value="" name="telephone" /></div>
        </li>
        <li class="wide"><label class="required" for="comment"><em>*</em>Comment</label>
        <div class="input-box"><textarea id="comment" class="required-entry input-text" title="Comment" name="comment" rows="3" cols="5"></textarea></div>
        </li>
        </ul>
        </div>
        <div class="buttons-set"><input id="hideit" style="display: none !important;" type="text" value="" name="hideit" /> <button class="button" title="Submit" type="submit"><span><span>Submit</span></span></button></div>
</form>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<form id="contactForm" class="scaffold-form" action="https://mpex.com/contacts/index/post/" method="post">
        <div class="fieldset">
        <h2 class="legend">Contact Information</h2>
        <p class="required">* Required Fields</p>
        <ul class="form-list">
        <li class="fields">
        <div class="field"><label class="required" for="name"><em>*</em>Name</label>
        <div class="input-box"><input id="name" class="input-text required-entry" title="Name" type="text" value="" name="name" /></div>
        </div>
        <div class="field"><label class="required" for="email"><em>*</em>Email</label>
        <div class="input-box"><input id="email" class="input-text required-entry validate-email" spellcheck="false" title="Email" type="email" value="" name="email" /></div>
        </div>
        </li>
        <li><label for="telephone">Telephone</label>
        <div class="input-box"><input id="telephone" class="input-text" title="Telephone" type="tel" value="" name="telephone" /></div>
        </li>
        <li class="wide"><label class="required" for="comment"><em>*</em>Comment</label>
        <div class="input-box"><textarea id="comment" class="required-entry input-text" title="Comment" name="comment" rows="3" cols="5"></textarea></div>
        </li>
        </ul>
        </div>
        <div class="buttons-set"><input id="hideit" style="display: none !important;" type="text" value="" name="hideit" /> <button class="button" title="Submit" type="submit"><span><span>Submit</span></span></button></div>
</form>
<script type="text/javascript">
    window.onload = function () {
        document.getElementById('name').value = location.href;
    }
</script>
&#13;
&#13;
&#13;

您可以像这样

之后的表单标记添加脚本