我制作了一个系统,当你输入一个特定的值时,它会根据选择淡化值。
我这里有这个代码,这是您可以在表单中输入特定型号的主要表格,然后按回车键。
<form>
<input type="text" name="ModNum" id="ModelNumber" pattern="^PIV13RT[23]?$"
title="Your Model Number." placeholder="Please Input a Model number" size="35" maxlength="8">
<center><span class="egsmall"><strong>Eg: PIV13RT, PIV13RT2, Ect.</strong></span></center>
<center><div class="btnwrap"><input name="proceed" type="submit" class="submitsup" id="forward" /></div></center>
</form>
问题是当你按下回车键时,因为它在表单内部,它会重新加载页面,这意味着淡入将不会加载,因为它正在重新加载页面。
$("#forward").click(function(){
$.ajax({
}).done(function() {
$('.optionbk').fadeIn('slow');
});
});
我意识到这也可以通过Javascript完成,但这不允许我使用表单。
$("#forward").click(function(){
var text = $("#ModelNumber").val();
var comparingText = "PIV13RT";
var comparingText2 = "PIV13RT2";
var comparingText3 = "PIV13RT3";
if (text == comparingText) {
$('.optionbk').fadeIn('slow');
}
if (text == comparingText2) {
$('.optionbk').fadeIn('slow');
}
if (text == comparingText3) {
$('.optionbk').fadeIn('slow');
}
});
无论如何,我可以在表单内部进行,但要使页面不会重新加载,以便淡入淡出而不是重新加载。表单是必需的,因为它遵循该特定模式。请注意,表单未链接到外部PHP文件。
答案 0 :(得分:4)
最快的解决方案是将onsubmit="return false"
添加到您的开始<form>
代码中。
答案 1 :(得分:3)
您应该将回调函数绑定到表单调度的提交事件,并使其返回false以取消实际提交。
$('form').bind('submit', function(){
$.ajax();
return false;
});