1
我有一些問題,運行下面的代碼,則JS:PHP jquery的,驗證遠程,陣列
$(document).ready(function(){
$.validator.addMethod("name", function(value, element) {
return $("#identiPIC_selected_0").val() !== '' && $("#identiPIC_selected_1").val() !== '' ;
}, "Required!");
$("#signin").validate({
groups:{
name : 'identiPIC_selected[]'
},
rules: {
'identiPIC_selected[]': {
required: true,
remote: {
url:"check3.php",
type:"post",
cache: false,
async:false,
data: {
'identiPIC_selected[0]': function() {
return $.trim($("#identiPIC_selected_0").val());
},
'identiPIC_selected[1]': function() {
return $.trim($("#identiPIC_selected_1").val());
}
}
}
}
}
});
});
的PHP是以下內容:
<?php
$captcha = $_POST['identiPIC_selected'];
$identiPIC[0] = "Apple";
$identiPIC[1] = "Flower";
if($captcha === $identiPIC){
echo "true";
} else {
echo "false";
}
?>
和HTML:
<form id="signin" action="check3.php" method="POST">
<select id="identiPIC_selected_0" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<select id="identiPIC_selected_1" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<input type="submit" id="save" name="save" value="Save"/>
</form>
此代碼適用於當用戶選擇第二個「選擇」選項錯誤時按下提交然後修復其錯誤,然後他按下提交只是不提交了,所以我的意思是比如:
用戶選擇:蘋果+貓,然後點擊保存按鈕,會顯示錯誤, 用戶解決了這個問題:蘋果+花,然後點擊保存按鈕,它不提交,即使所有的選擇都很好。
我加了這一點:
$("#identiPIC_selected_0").change(function() {
$("#identiPIC_selected_0").removeData("previousValue");
});
$("#identiPIC_selected_1").change(function() {
$("#identiPIC_selected_1").removeData("previousValue");
});
,但它似乎沒有對我做任何事。 任何任何想法? 謝謝!