使用JS加载HTML元素

时间:2016-05-14 08:34:34

标签: javascript html


我尝试使用隐藏字段安装自定义MailChimp form 我要传递的值包含在URL中,我使用JS提取它们。没问题。
表单代码如下所示:

<div id="mc_embed_signup">
<form action="//treat-candida.us3.list-manage.com/subscribe/post?u=d6e792c187ee9f2f2ad&amp;id=787f11a" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
    <h2>Subscribe to our list</h2>
<div class="indicates-required"><span class="asterisk"></span> </div>
<div class="mc-field-group">
    <label for="mce-EMAIL"><span class="asterisk"></span>
</label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="mc-field-group">
    <label for="mce-FNAME"><span class="asterisk"></span>
</label>
    <input type="text" value="" name="FNAME" class="required" id="mce-FNAME">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>    
    <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_d6e792c187ee9f2f2da2f179d_787f1101bd" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='COOKIE';ftypes[2]='text';fnames[3]='GENDER';ftypes[3]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>

我要做的是将网址中的值附加到//treat-candida.us3.list-manage.com/subscribe/post?u=d6e792c187ee9f2f2ad&amp;id=787f11a
在代码内。我尝试使用.innerHTML来编辑那个部分。它以这种方式成功传递值,但由于编辑,表单不能正确提交。看起来我必须立即用div和文本编辑整个代码。有优雅的方法吗?

1 个答案:

答案 0 :(得分:-1)

做类似的事情:

$("#mc-embedded-subscribe-form").action = $("#mc-embedded-subscribe-form").action + values