简体   繁体   English

如何在弹出的同一页面的下拉列表中使用预选选项创建超链接?

[英]How to create hyperlink with pre-selected option in drop down list on the same page in pop up?

I am trying to get to work pre selecting an option in a pop up window. 我正在尝试开始工作,然后在弹出窗口中选择一个选项。 I've done my research on the internet and this is what I got so far but it doesn't work. 我已经在互联网上进行了研究,这是到目前为止的结果,但是没有用。 I now always have option number one pre selected 我现在总是预先选择了第一个选项

Hyperlink triggering showing the pop up, where option two should be pre selected. 超链接触发显示弹出窗口,其中应预先选择选项二。

<a href="?select=two" class="btn btn-red-2 show-modal" data-modal-id="order-form-modal">Order!</a>

Modal Window, which shows up and the option two should be pre selected. 出现的“模态窗口”和“选项二”应预先选择。

<div id="order-form-modal" class="modal-window">
<select class="prettyform" name="select" id="select">
                            <option id="one" value="1" data-price="950">Nízke stojánky</option>
                            <option id="two" value="2" data-price="1790">Vysoké stojánky</option>
                            <option id="three" value="3" data-price="990">Set přenosné kruhy</option>
                            <option id="four" value="4" data-price="790">Přenosné kruhy</option>
                            <option id="five" value="5" data-price="490">Popruhy na kruhy</option>
                        </select>
</div>

JavaScript which should parse the parameter given in hyperlink at the beginning. JavaScript应该在开始时解析超链接中给定的参数。

<script>
    $(document).ready(function() {
        var select = GetUrlParameter("select");
        $("#" + select).attr("selected", "");
    });

    function GetUrlParameter(name) {
            var value;
            $.each(window.location.search.slice(1).split("&"), function (i, kvp) {
                    var values = kvp.split("=");
                    if (name === values[0]) {
                            value = values[1] ? values[1] : values[0];
                            return false;
                    }
            });
            return value;
    }
</script>

You need to set the selected property on the option to true: 您需要将option上的selected属性设置为true:

var select = GetUrlParameter("select");
$("#" + select).prop("selected", true);

Example fiddle 小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何加载带有预选类别选项的页面 - How to load page with category option pre-selected ng-change 正在清除预先选择的下拉选项 - ng-change is wiping out the pre-selected drop down option 如何根据选择的选项更改 URL 以便新的 url 将 go 页面与该选项预选? - How to change URL based on option selected so that the new url will go to page with that option pre-selected? 如何在Rails表单中未预先选择选择选项 - How to Have a Select Option NOT Pre-Selected in a Rails Form 预先选择的多个复选框列表 - pre-selected multiple checkbox list in angular 如何根据下拉菜单中选择的选项在网页中创建动态内容 - How to create dynamic content in a web page according to the option selected in drop down menu 如何检查我是否连续两次选择了相同的下拉列表选项? - How do I check if I have selected the same drop-down list option twice in a row? 如何在选择下拉列表的选项中设置所选属性 - how to set selected attribute in option for select drop down list 如何将json数组元素映射到下拉列表中选择的选项? - How to map json array elements to option selected in drop down list? 如何使用取决于另一个下拉列表中所选选项的下拉列表显示表格简码 - how to display table shortcode with a drop-down list that depends on the selected option in another drop-down list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM