Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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_Selection_Dropdownbox - Fatal编程技术网

Javascript 继续竞选?我做错了什么?

Javascript 继续竞选?我做错了什么?,javascript,jquery,selection,dropdownbox,Javascript,Jquery,Selection,Dropdownbox,我试图检查url中是否有hos paramaeter,如果有,则将该值作为所选属性传递给页面刷新时的下拉列表,以便即使刷新后下拉列表选项仍保持选中状态 var value = window.location.href.match(/[?&]hos=([^&#]+)/) || []; if (value.length == 2) { $('#hospitalDropDown[value="' + value[1] + '"]').at

我试图检查url中是否有hos paramaeter,如果有,则将该值作为所选属性传递给页面刷新时的下拉列表,以便即使刷新后下拉列表选项仍保持选中状态

   var value = window.location.href.match(/[?&]hos=([^&#]+)/) || [];

        if (value.length == 2) {
            $('#hospitalDropDown[value="' + value[1] + '"]').attr('selected', 'selected');

    }
以下是下拉列表:

<select id="hospitalDropDown" onchange="window.open(this.options[this.selectedIndex].value,'_top')">          <option value="http://mysite.com/events/Pages/default1.aspx">All Hospitals</option>   <option value="http://mysite.com/events/Pages/default1.aspx?hos=Dyer">Dyer</option>   <option value="http://mysite.com/events/Pages/default1.aspx?hos=Carmel">Carmel</option> </select> 

看起来您的选项将querystring值All Hospitals、Dyer、Carmel作为文本,但将整个url作为值

因此,将您的期权价值与*=


url是什么样子的,选项是什么样子的?为什么不先完成这个呢?
if (value.length == 2) {
    $('#hospitalDropDown option[value*="' + value[1] + '"]').attr("selected", "selected");