jQuery如何获取复选框选中项后的文字?

JavaScript012

jQuery如何获取复选框选中项后的文字?,第1张

1、创建如下结构的测试文件-- Content,-- jquery-1.11.3.min.js,-- JquerySelect.html。

2、【获取】下拉框【选中值】:使用【.val()】。

3、【获取】下拉框【选中文本】:使用【.find("option:selected").text()】。

4、【获取】下拉框选中项的【索引】:使用【.get(0).selectedIndex】。

5、通过【value】值【设置】下拉框的选中项:使用【.val("value值")】。

6、通过【text】值【设置】下拉框的选中项。

7、通过【value】值【删除】下拉框的一个选项。

8、通过【text】值【删除】下拉框的一个选项。

//获取选中的文字

function getSelectText(editor) {

    if (!editor) return editor.focus()

    if (editor.document && editor.document.selection)

        return editor.document.selection.createRange().text 

    else if ("selectionStart" in editor)

        return editor.value.substring(editor.selectionStart, editor.selectionEnd) 

}

//调用方式

var text= getSelectText(document.getElementById("txtName"))