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