Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过javascript函数选择所选选项_Javascript_Jquery_Dom_Jquery Chosen - Fatal编程技术网

通过javascript函数选择所选选项

通过javascript函数选择所选选项,javascript,jquery,dom,jquery-chosen,Javascript,Jquery,Dom,Jquery Chosen,我一直在尝试实施年提出的一个解决方案,但没有成功。要么向混合中添加select使解决方案无效,要么我犯了一些编译器和我都找不到的编码错误 我的html: <select name="superType" class="chosen-select chosen-select-creation-allowed" id="superType" style="width: 300px; display: none;" onchange="loadInheritance()" multiple=""

我一直在尝试实施年提出的一个解决方案,但没有成功。要么向混合中添加select使解决方案无效,要么我犯了一些编译器和我都找不到的编码错误

我的html:

<select name="superType" class="chosen-select chosen-select-creation-allowed" id="superType" style="width: 300px; display: none;" onchange="loadInheritance()" multiple="">
  <option style="padding-left:20px;" value=""></option><option style="padding-left:0px" value="28">concept</option>
  <option style="padding-left:20px" value="30">human</option>
</select>
相反,根据DOM模型检查器和可视化表示,不会发生任何事情

我想要的是在函数中进行此选择,但当我尝试构建对上面选项的引用时,会出现错误:

Syntax error, unrecognized expression: '#superType option[value="30"]'
下面是生成该脚本的javascript(在“cid”上进行处理):


css选择器周围不需要单引号

$(`${target} option[value="${optionValue}"]`).attr('selected', 'selected');

为什么css选择器周围有单引号?
            //now go back through and select the ones this CommonNoun already had from before
            $.ajax({
                url: '/BackToTech/server?function=getExistingSuperTypes',
                type: 'POST',
                success: function (response){
    //              var target = $("#superType");           
                    var target = "#superType";          
                    selectOptions(response, target, 0);
                    $('.chosen-select').trigger("chosen:updated");
                }
            });
function selectOptions(obj, target) {
    var concepts = obj; 
    $.each(concepts, function(concept, value) {  
        alert(concept, value);
        if (concept == "cid") {
            optionValue = obj[concept].oid;
            $("'" + target + " option[value=\"" + optionValue + "\"]'").attr('selected', 'selected');
        } else { 
            selectOptions(value, target);
        }
    });
} 
$(`${target} option[value="${optionValue}"]`).attr('selected', 'selected');