使用jQuery更改操作和图像src url

时间:2010-12-02 06:04:36

标签: php javascript jquery

我使用php代理从我的另一个网站解析表单。它工作正常,但提交按钮网址的表单操作和img src是相对的。我怎样才能在表格中的每个网址前面加上完整的http // www.domain.com /?

编辑:

以下是表单代码一旦输入到新域名:

 <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>

这是我用来尝试更改动作网址的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);
  });
});

所有其他jQuery函数在页面上运行良好,所以我知道它不是jQuery本身的问题。

1 个答案:

答案 0 :(得分:0)

开始阅读原始网址

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

  });

将更改所有图片网址 可能是另一种方式,但这同样有效

结帐

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