Add form value to end of url - Jquery

*爱你&永不变心* 提交于 2020-01-06 19:52:41

问题


I have a input field that has the id #formValueId

<input id="formValueId" type="text" class="form-control" placeholder="email address" name="unsubemail">

I'm using this function here as well,

function addURL(element) {
$(element).attr('href', function(){
    return this.href + 'unsubscribe-complete?q=direct_unsubscribe&fn=Public_DirectUnsubscribeForm&id=IDSTRING&' + 'unsubscribeEmail';
});
}

I also created a variable like this,

var unsubscribeEmail = $("#formValueId").val();

at the end of my addURL function for return this.href line I'm adding the variable to the end of it and it works great but the url isn't passing the val(); it's just putting the var name at the end. what am I doing wrong here?

+ 'unsubscribeEmail';


回答1:


by using 'unsubscribeEmail' you make it just string so use unsubscribeEmail instead of 'unsubscribeEmail'

function addURL(element) {
$(element).attr('href', function(){
    return this.href + 'unsubscribe-complete?q=direct_unsubscribe&fn=Public_DirectUnsubscribeForm&id=IDSTRING&' + unsubscribeEmail;
});
}


来源:https://stackoverflow.com/questions/34278333/add-form-value-to-end-of-url-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!