JQuery实现下拉框

jquery 的 下拉框第一次Coding,感觉炸疯了,为了小伙伴不在和我一样,我决定把这简单又基础的代码Show出来,

<div class="bjui-row col-1">
                <label class="row-label" style="width: 150px">任务人:label>
                <div class="row-input required">
                    <select id="taskMan" >
                        <option value="">请选择任务人option>
                    select>
                div>
            div>
<script type="text/javascript">
    /*下拉框js代码*/
    function getTaskNameList() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${serverPath}/task/getTaskMan",
            success: function (response) {
            renderSelect(response);
        }
    });
    }
    function renderSelect(response) {
        var sItem = $("#taskMan");
        var options = ""
        response.forEach(element => {
            sItem.append("element.id+">"+element.memberName+"")
        });
    }
    getTaskNameList()

    $("#taskMan").change(function(){
        var val = $("#taskMan option:selected").val();
        var text = $("#taskMan option:selected").text();
        console.log("你是谁?"+val)
        console.log("你是谁?"+text)
    })
</script>

新增事件按钮

<script>
	function addTaskSubmit() {
 		var taskMan = $("#taskMan option:selected").text();
	}
</script>

你可能感兴趣的:(jquery,ajax,easyui)