本文介绍了Jquery函数在某些条件下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< input id =BUXARname =BUXARonclick =SearchDistict(BUXAR); type =checkboxvalue =33>



< input id =CHAMPARAN_EASTname =CHAMPARAN EASTonclick =SearchDistict(CHAMPARAN EAST) ; type =checkboxvalue =34>



函数SearchDistict(obj)

{

调试器;

if(obj.checked)

{

districtCollection.push(obj.value);

}

else

{

districtCollection.pop(obj.value);

}



SearchDistict(BUXAR)工作正常,但是当我们调用SearchDistict(CHAMPARAN EAST)时



显示错误:未捕获的SyntaxError :缺少)参数列表后

<input id="BUXAR" name="BUXAR" onclick="SearchDistict(BUXAR);" type="checkbox" value="33">

<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);
}

SearchDistict(BUXAR) work fine but when we call SearchDistict(CHAMPARAN EAST)

show error : Uncaught SyntaxError: missing ) after argument list

推荐答案

SearchDistict('CHAMPARAN EAST')





此外,此对象没有已选中的定义。弹出另一个错误,你需要发送这个作为 obj 。或至少将您的代码更改为此代码





Also, this object doesn't have definition for checked. Another error would pop up, you need to sent this as obj. Or at least change your code to this one

function SearchDistrict(name) {
   name = name.replace(' ', '_');
   obj = document.getElementById(name); // Element with that ID would be found
   if (obj.checked)  // Checked property be read
   {
      districtCollection.push(obj.value);
   }
   else
   {
      districtCollection.pop(obj.value);
   }
}





为此,我说,你需要将HTML改为这个,





For this sake I said, you need to change the HTML to this one,

onclick="SearchDistict(this);"





现在您可以确定其他属性,例如ID或其名称。 :)



我想知道代码是如何工作的。 :笑:因为,你传递了一个字符串文字,字符串不包含已定义的定义


这篇关于Jquery函数在某些条件下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:01