2
嗨下面是我使用我的表單來驗證在兩個輸入字段中輸入的id的代碼。所有的代碼工作正常。唯一的事情是,如何停止表單從提交,如果這兩個字段是無效的,因爲我禁用和啓用提交按鈕如果記錄返回爲true.but如果任何一個字段是有效的,然後提交按鈕啓用並允許用戶提交表單。如何避免表單提交,如果這兩個值都有效
<form>
<input type="text" id="1" value=""/>
<input type="text" id="2" value=""/>
<input type="submit" value="submit" id="submitbutton" >
</form>
<script type="text/javascript">
$$(document).ready(function() {
$$('#1').blur(function() {
var id = $$('#1').val();
$$.getJSON("user.cfc?method=getRequests&returnformat=json&queryFormat=column",{"status":id}, function(res1,code) {
if(res1.ROWCOUNT > 0){
for(var i=0; i<res1.ROWCOUNT; i++) {
s = "<span class='dPostTxt'>" + res1.DATA.ID[i] + " " + res1.DATA.FIRST_NAME[i] + " " + res1.DATA.LAST_NAME[i] + " " + "is valid." + "</span>";
};
$$('#submitbutton').removeAttr('disabled');//now id is valid so enabling submit button
}
else {
$$('#submitbutton').attr('disabled', 'disabled'); //error with id so disabling button
alert(" ID Is Not Valid.Please Enter Valid ID");
var s = "Entered ID Is Not Valid.";
}
$$("#results").html(s);
},"json");
}); });
</script>
<script type="text/javascript">
$$(document).ready(function() {
$$('#2').blur(function() {
var id = $$('#2').val();
$$.getJSON("user.cfc?method=getRequests&returnformat=json&queryFormat=column",{"status":id}, function(res,code) {
if(res.ROWCOUNT > 0){
for(var i=0; i<res.ROWCOUNT; i++) {
s = "<span class='dPostTxt'>" + res.DATA.ID[i] + " " + res.DATA.FIRST_NAME[i] + " " + res.DATA.LAST_NAME[i] + " " + "is valid." + "</span>";
};
$$('#submitbutton').removeAttr('disabled');//now id is valid so enabling submit button
}
else {
$$('#submitbutton').attr('disabled', 'disabled'); //error with id so disabling button
alert(" ID Is Not Valid.Please Enter Valid ID");
var s = "Entered ID Is Not Valid.";
}
$$("#results1").html(s);
},"json");
}); });
</script>
什麼是所有的雙美元符號? ('$$'??) – Neal 2011-05-16 19:55:49
通常是將jQuery鞋釦到已分配給$ – FatherStorm 2011-05-16 19:58:45
的頁面的結果爲什麼兩個'
分配支票火上
$("form").submit()
代替領域的onblur。這樣你可以同時檢查兩個狀態,也許發生警告的頁面,如果你的表單值是錯誤的&等來源
2011-05-16 20:01:23 FatherStorm
$$是爲我做的var $$ = jQuery.noConflict();這是工作良好的代碼我工作很好唯一的事情是從頂級窗體提交如果任何o值是錯誤驗證 – cfnew 2011-05-16 20:17:15