我在php网站上建立了电子邮件的初始注册框。我正在使用magento,所以我不能简单地将get中的变量回显到下一页的email字段中。那是我目前使用的唯一方法。
<form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail" class="footerNewsletter">
<label for="newsletter" class="footerHeads"><?php echo $this->__('Connect With US') ?></label>
<div class="inputTextContainer">
<input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('enter email for specials and updates!') ?>"
title="<?php echo $this->__('Enter email for specials and updates!') ?>" class="required-entry validate-email">
<i class="icon-mail"></i>
</div>
<input type="hidden" name="source" value="nt" />
<button type="submit" class="button" style="display:none;" title="<?php echo $this->__('Subscribe') ?>"><span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</form>
<script type="text/javascript">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
//]]>
</script>
第二页将有一个标准输入框,如下所示:
<input type="text" name="email" size="40" maxlength="100" value=""/>
我知道在php中,我可以使用该值并回显$ email。
我在用JavaScript进行思考,我可以这样使用:
<script type="text/javascript">
document.getElementById("email").innerhtml = window.location.search;
</script>
不过,我不确定如何使用它document.write
来填写电子邮件输入。
尝试使用jQuery,它将使生活更加轻松。假设您的页面网址是这样的:www.example.com/[email protected]
<script type="text/javascript">
$(function() {
$('input[name="email"]').val(window.location.search.replace('?email=', ''));
});
</script>
如果要访问,www.example.com/[email protected]
则“名称”输入字段将获得值“ [email protected]”。
示例示例:https://jsfiddle.net/f8817t4q/ (window.location.search
出于演示目的,必须替换为静态字符串)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句