0

嗨,我有以下复选框和一个按钮。我想选中该框,然后在使用 jquery 单击按钮时调用一个函数。

        <form id="rForm" >
          <table id="testing" class=""    border="1" cellpadding="0" cellspacing="0">
            <tr>
              <td>
                <td> <label class="" for="_person" >Person</label></td>
               <td> <input type="checkbox" class="_person" id="rov" name="person"/></td>
                 <td><input type="button" id="personList" class=""  value="Search" /></td>
              </tr>
          </table>
        </form>


        $(document).ready(function () {
              $("#vendorList").click(function () {

                  if ($("input:checkbox:checked").val() = "vendor") {
                      fnloadlist();
                  }
              });                 
          });

当我使用萤火虫运行时。它在 if 语句中给出错误“ReferenceError:无效赋值左侧”。我尝试了一些不同的东西,但似乎没有任何效果。请帮助,因为我是 jquery 的新手。谢谢

4

2 回答 2

1
  • 使用===代替=进行比较
  • 您的复选框没有 value 属性
  • vendorList您的标记中没有 ID 为的元素
  • 您可以按 ID 选择复选框(因为它有一个)并使用方法检查它是否被选中.prop()

    if ( $('#rollUPForm_vendor').prop('checked') ) {
        //                      |                                 
        //                      => returns true/false
    }
    
于 2013-09-16T01:21:44.603 回答
0

试试这个方法

<form id="rollUpForm" >
  <table id="testing" class=""    border="1" cellpadding="0" cellspacing="0">
    <tr>
      <td>
        <td> <label class="" for="_person" >Person</label></td>
       <td> <input type="checkbox" class="_person" id="rollUPForm_vendor" value="person" name="person"/></td>
         <td><input type="button" id="personList" class=""  value="Search" /></td>
      </tr>
  </table>
</form>
<script type="text/javascript"> 
       $(function() {
         $(document).ready(function () {
            function fnloadlist () {
                alert('Yes');
            }
              $("#personList").click(function () {              
                  if ($("input:checkbox:checked").val() == "person") {
                      fnloadlist();
                  }
              });                 
          });   


        });
    </script>
于 2013-09-16T01:35:57.693 回答