Javascript 表单重定向到链接
在我的网站上,我有一个列表页面 看起来是这样的: 左边的部分是一个表单,我希望用户被重定向到一个更新的列表页面,其中包含他的选择(图片上的示例,Project for sale和Project for sale) 因此,基本上,用户做出选择,然后单击submit。然后,用户被重定向到一个类似的页面,其中只包含这种类型的项目。用户可以选择4种不同的选项:Javascript 表单重定向到链接,javascript,jquery,Javascript,Jquery,在我的网站上,我有一个列表页面 看起来是这样的: 左边的部分是一个表单,我希望用户被重定向到一个更新的列表页面,其中包含他的选择(图片上的示例,Project for sale和Project for sale) 因此,基本上,用户做出选择,然后单击submit。然后,用户被重定向到一个类似的页面,其中只包含这种类型的项目。用户可以选择4种不同的选项: 出售的项目和过去的项目 正在销售和正在进行的项目 项目的租金和过去 项目的租金和发生现在 这是我写的代码: jQuery(document
- 出售的项目和过去的项目
- 正在销售和正在进行的项目
- 项目的租金和过去
- 项目的租金和发生现在
jQuery(document).ready(function(){
jQuery('.button-submit').click(function(){
var radioValue = jQuery('input:radio:checked').val();
if ((radioValue == 'vente') || (radioValue == 'passe')){
window.location.href = 'page1.com';
}
if ((radioValue == 'vente') || (radioValue == 'present')) {
window.location.href = 'page2.com';
}
if ((radioValue == 'location') || (radioValue == 'passe')){
window.location.href = 'page3.com';
}
if ((radioValue == 'location') || (radioValue == 'present')){
window.location.href = 'page4.com';
}
})
});
由于某种原因,我的代码无法正常工作。我做错了什么
<div class="w-form">
<form id="wf-form-Choice-form" name="wf-form-Choice-form" data-name="Choice form">
<h2 class="h2-big titreprojet"><strong>Découvrez NoTRE PORTFOLIO</strong><br></h2>
<div class="lineprojet"></div>
<div class="description">Notre caractère distinctif, c’est d’avoir réalisé des projets de qualité, tout en procurant une expérience unique à nos clients. <br></div>
<div class="w-row">
<div class="column-16 w-col w-col-6">
<div class="smalltext">Type de projet</div><label class="radio-button-field-2 w-radio"><input type="radio" data-name="Typedeprojet" id="vente" name="Typedeprojet" value="vente" class="w-form-formradioinput projetenvente w-radio-input"><span for="vente" class="textcheck w-form-label">Projets en vente</span></label><label class="radio-button-field-3 w-radio"><input type="radio" data-name="Typedeprojet" id="location" value="location" name="Typedeprojet" class="w-form-formradioinput projetenlocation w-radio-input"><span for="location" class="textcheck w-form-label">Projets en location</span></label></div>
<div class="w-col w-col-6">
<div class="smalltext">DATE DU PROJET</div><label class="radio-button-field-5 w-radio"><input type="radio" data-name="Timeline" id="actuel" name="Timeline" value="actuel" class="w-form-formradioinput projetactuel w-radio-input"><span for="actuel" class="textcheck w-form-label">Projet actuel</span></label><label class="radio-button-field-4 w-radio"><input type="radio" data-name="Timeline" id="passe" name="Timeline" value="passe" class="w-form-formradioinput projetpasse w-radio-input"><span for="passe" class="textcheck w-form-label">Projets passé</span></label></div>
</div><a href="#" class="button filter w-button">Recherchez</a></form>
<div class="w-form-done">
<div>Thank you! Your submission has been received!</div>
</div>
<div class="w-form-fail">
<div>Oops! Something went wrong while submitting the form.</div>
</div>
</div>
Découvrez-NoTRE投资组合
诺特卡拉奇酒店以其独特的品质,向采购商兜售独一无二的客户体验
项目位置上的通风项目类型
项目实施日期
非常感谢。您的提交已收到!
哎呀!提交表单时出错。
据我所知,提交表单后,您的页面将重新加载。
提交表单时不使用preventDefault()
jQuery(document).ready(function(){
jQuery('.button-submit').click(function(e){
e.preventDefault();
var radioValue = jQuery('input:radio:checked').val();
if ((radioValue == 'vente') || (radioValue == 'passe')){
window.location.href = 'page1.com';
}
if ((radioValue == 'vente') || (radioValue == 'present')) {
window.location.href = 'page2.com';
}
if ((radioValue == 'location') || (radioValue == 'passe')){
window.location.href = 'page3.com';
}
if ((radioValue == 'location') || (radioValue == 'present')){
window.location.href = 'page4.com';
}
})
});
此外,我建议您在提交表单后收听,而不是单击按钮:
$(“#表单”)。在(“提交”上,函数(e){…}
请显示相关的html。特别是表格。我相信您需要阻止的表单正在提交。您需要的不是&&
,而是一个名为webflow的CMS。这是html链接:用html编辑问题当你点击提交时会发生什么?没有什么?或者控制台中是否存在错误?如果没有错误,尝试记录“radioValue”中的内容-如果只是为了证明点击事件已连接。是的,同样的问题。HTML部分在这里非常重要,因为我们看不到单选值,也不知道按钮类型是否为submit,以及是否需要防止某些行为,如@NawedKhan所述。