<input id="CHAMPARAN EAST"
name="CHAMPARAN EAST"
onclick="SearchDistict('CHAMPARAN EAST');" type="checkbox" value="34">
我的功能
function SearchDistict(obj) {
debugger;
if (obj.checked) {
districtCollection.push(obj.value);
} else {
districtCollection.pop(obj.value);
//districtCollection.splice($.inArray(obj.value, districtCollection),1);
}
var postData = preparingSearch();
debugger;
postData.StateList = '';
postData.DistrictList = districtCollection;
SearchEngine();
//CallSearchBorrower(postData);
}
当我们调用SearchDistict('CHAMPARAN EAST')时它的工作但不调用if语句
答案 0 :(得分:1)
而不是传递复选框传递this
对象的id,如下所示。 this
对象将具有复选框的所有状态,但仅传递id
值将无法解决您的目的。
function SearchDistict(obj)
{
alert(obj.checked);
if (obj.checked)
{
districtCollection.push(obj.value);
}
else {
districtCollection.pop(obj.value);
//districtCollection.splice($.inArray(obj.value, districtCollection),1);
}
var postData = preparingSearch();
debugger;
postData.StateList = '';
postData.DistrictList = districtCollection;
SearchEngine();
//CallSearchBorrower(postData);
}
<input id="CHAMPARAN EAST"
name="CHAMPARAN EAST"
onclick="SearchDistict(this);" type="checkbox" value="34">
上面的代码将为您提供函数内部obj.checked
的值
答案 1 :(得分:0)
obj
是一个字符串,而不是复选框,因此它没有checked
属性,而是可以使用this
关键字传递对象引用本身行事件处理程序。
<input id="CHAMPARAN EAST" name="CHAMPARAN EAST" onclick="SearchDistict(this);" type="checkbox" value="34">
然后
function SearchDistict(obj) {
debugger;
if (obj.checked) {
districtCollection.push(obj.value);
} else {
districtCollection.pop(obj.value);
//districtCollection.splice($.inArray(obj.value, districtCollection),1);
}
var postData = preparingSearch();
debugger;
postData.StateList = '';
postData.DistrictList = districtCollection;
SearchEngine();
//CallSearchBorrower(postData);
}