我在制作我的网站时遇到了一个问题,当我选择一个特定的选项时,它应该会将我重定向到另一个索引,例如,当我选择"Membre bénevole“时,页面”reg-beneve.html“就会被加载。当我选择“可响应的关联”时,页面"reg-assocation.html“将被加载。
但当我测试它时,它每次都会为这两个选项加载reg-beneve.html ...
`<div class="form-group">
<select id="cat" style="width:80%;" class="form-control" name="option">
<option value="Responsable association" onChange="catgValue =this.value;"> Responsable
association </option>
<option value="Membre bénevole" onChange="catgValue =this.value;">Membre bénevole
</option>
</select>
</div>
<div class="form-group">
<input type="submit" id="s" class="btn btn-primary" value="Soumettre">
</div>`
和Jquery代码:
$(document).on('click', '#s', function () {
if (catgValue = 'Membre bénevole') {
window.location.href = "reg-benevole.html";
}
else if (catgValue = 'Responsable association') {
window.location.href = "reg-assocation.html";
}
});
发布于 2019-05-23 04:18:52
您不仅可以使用单个=号进行设置,而且最好不要使用change
的click
事件进行选择。您不需要在选项中使用onchange事件。
$(document).on('change', '#s option', function () {
if (this.value == 'Membre bénevole') {
window.location.href = "reg-benevole.html";
}
else if (this.value == 'Responsable association') {
window.location.href = "reg-assocation.html";
}
});
发布于 2019-05-23 04:23:51
感谢您的回答!我太感谢这一点了,我像这样修改了代码,但还什么都没有..(顺便说一句,谢谢你提醒我"==“我有点醉了,我用了”xDD“,因为它属于提交按钮,而不是选择选项
$(document).on('click', '#s', function () {
if (catgValue == 'Membre bénevole') {
window.location.href = "reg-benevole.html";
}
else if (catgValue == 'Responsable association') {
window.location.href = "reg-assocation.html";
}
})
https://stackoverflow.com/questions/56264283
复制相似问题