简体   繁体   English

使用jQuery更改动作和图片src网址

[英]Change action and image src url's with jQuery

I am parsing a form from another one of my sites using a php proxy. 我正在使用php代理从另一个站点解析表单。 It is working fine but the form action and img src of the submit button url's are relative. 它工作正常,但是表单操作和提交按钮URL的img src是相对的。 How can I prepend the full http//www.domain.com/ in front of each of the url's in the form? 如何在表格的每个网址前面加上完整的http // www.domain.com /?

Edit: 编辑:

Here's the form code once fed through to the new domain: 这是一次传递到新域的表单代码:

 <div style="display: none;" id="SubscribeForm" class="newform">

            <h5>Subscribe to our newsletter</h5>

            <form action="/CampaignProcess.aspx?ListID=27057" method="post" onsubmit="return checkWholeForm93426(this)" name="catemaillistform93426">

                <div class="form">

                <div class="item">

                <label for="CLFullName">Full Name</label>

                <br />

                <input type="text" maxlength="255" id="CLFullName" name="FullName" class="cat_textbox_small" style="background-color: #ffffa0;" />

                </div>

                <div class="item">

                <label for="CLEmailAddress">Email Address</label>

                <br />

                <input type="text" maxlength="255" id="CLEmailAddress" name="EmailAddress" class="cat_textbox_small" style="background-color: #ffffa0;" />

                </div>

                <div class="item">

                <label>Enter Word Verification in box below</label>

                <br />

                <div class="captchaimg"><img src="/captchahandler.ashx?ID=22791bf65054422cadeb4aea9390cfaa&amp;Color=DimGray&amp;ForeColor=White&amp;Width=160" alt="Captcha Image" /></div>

    <input id="CaptchaV2" class="cat_textbox" type="text" name="CaptchaV2" style="width:160px" />

    <input id="CaptchaTV2" type="text" name="CaptchaTV2" style="display:none;" />

    <input id="CaptchaHV2" type="hidden" value="22791bf65054422cadeb4aea9390cfaa" name="CaptchaHV2" />



                </div>

                <div class="item">

                <p>We respect your privacy and will never share your details.</p>

                </div>

                <div class="item">

                <input type="image" src="/images/submit-button-white-bg_07.gif" id="catlistbutton" value="Subscribe" class="cat_button" />

                </div>

                </div>

                <script type="text/javascript" src="http://testsite.businesscatalyst.com/CatalystScripts/ValidationFunctions.js"></script>

                <script type="text/javascript">function checkWholeForm50598(theForm){var why = "";if (theForm.EmailAddress) why += checkEmail(theForm.EmailAddress.value);if (theForm.CaptchaV2) why += isEmpty(theForm.CaptchaV2.value, "Enter Word Verification in box below"); if (why != ""){alert(why);return false;}theForm.submit();return false;}</script>

            </form>
</div>

and here's the jQuery I am using to try and change the action url: 这是我用来尝试更改操作网址的jQuery:

jQuery(document).ready(function($) {
  $('form').each(function(index) {
    var urls = $(this).attr('action');
    var dom = 'http://www.sampleurl.com';
    $(this).attr('action',dom+urls);
  });
});

All other jQuery functions are working well on the page so I know it is not an issue with jQuery itself. 所有其他jQuery函数在页面上都运行良好,因此我知道这与jQuery本身无关。

well start of reading the original url 良好的开始阅读原始网址

$('img').each(function(index) {
    var urls =$(this).attr('src');
    var dom = 'http://domain.com';
    $(this).attr('src',dom+urls);

  });

that will change all the image urls might be another way but this works just as good 会更改所有图像网址的方法可能是另一种方法,但这同样有效

checkout here 在这里结帐

http://www.jsfiddle.net/LewEB/ http://www.jsfiddle.net/LewEB/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM