isSelected
會回傳布林值(true 或 false),表示目前是否有選取 <option>
或 <input>
類型為核取方塊或單選按鈕的元素。
用法
$(selector).isSelected()
範例
index.html
<select name="selectbox" id="selectbox">
<option value="John Doe">John Doe</option>
<option value="Layla Terry" selected="selected">Layla Terry</option>
<option value="Bill Gilbert">Bill Gilbert"</option>
</select>
isSelected.js
it('should detect if an element is selected', async () => {
let element = await $('[value="Layla Terry"]');
console.log(await element.isSelected()); // outputs: true
element = await $('[value="Bill Gilbert"]')
console.log(await element.isSelected()); // outputs: false
});