Cannot get a checkbox

流过昼夜 提交于 2020-01-07 08:07:29

问题


I cannot get the checkbox selector from the documentation working. Any idea why? $('checkbox').size() is always zero.

HTML page

<html>    
    <head>
        <title>Geb</title>
    </head>    
    <body>
        <input type="checkbox" name="pet" value="dogs" checked="true" />    
    </body>    
</html>

Groovy code

Browser.drive {
    go "file:///home/zoran/page.html"
    println $('checkbox').size() // is always zero
}

回答1:


To select all checkboxes on a page using a jQuery selector you need to use:

$('input[type=checkbox]').size()



回答2:


to select all checkboxes use jquery selector as

$('input:checkbox').size()



回答3:


simply provide id to your checkbox

<input type="checkbox" id="chkPet" name="pet" value="dogs" checked="true" /> 

and then

$("#chkPet")


来源:https://stackoverflow.com/questions/18848429/cannot-get-a-checkbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!