页面重新加载后选择make选项 [英] make option selected after page reloads

查看:87
本文介绍了页面重新加载后选择make选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi

i have select box with options as

<div class="sortvalue">

<span>Sort By : </span>

<select id="ddlCountry" runat="server" onchange="GetCountryDetails()">
<option id="sortval" value="" ></option>
<option id="sortvalltoh" value="ltoh" >Rating Low to High</option>
<option id="sortvalhtol" value="htol" >Rating High to Low</option>
<option id="sortvalPrfd" value="Prfd" >Preferred</option>
</select>
</div>

and i reload the page again with option selected value.

ie. if i select value high to low,  i reload page with attached "&test=ltoh"  in querystring .

and then  i want to make that option as selected from jquery after loading page ,

how is this possible

regards

maulik shah

推荐答案

Hi Mauli,



以下功能用于从URL读取查询字符串并将值映射到ddl选项



这可以在document.ready()函数中使用,如

Hi Mauli,

Below function is used to read the query string from URL and map the value to ddl option

This can be used in document.ready() function like


document .ready(函数(){
var qs =( function (a){
if (a == return {};
var b = {};
< span class =code-keyword> for ( var i = 0 ;我<则为a.length; ++ i)
{
var p = a [i] .split(' =');
if (p.length!= 2 继续;
b [p [ 0 ]] = decodeURIComponent(p [ 1 ]。replace(/ \\ \\ + / g, ));
}
返回 b;
})( window location .search.substr( 1 )。split(' &'));

if (qs [' test']!= undefined ){
(document.ready(function() { var qs = (function(a) { if (a == "") return {}; var b = {}; for (var i = 0; i < a.length; ++i) { var p=a[i].split('='); if (p.length != 2) continue; b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; })(window.location.search.substr(1).split('&')); if(qs['test'] != undefined){


' #ddlCountry')。val(qs [' 测试]);
}
}));
('#ddlCountry').val(qs['test']); } }));





希望这会对你有所帮助。



问候,

RK



Hope this helps you a bit.

Regards,
RK


这篇关于页面重新加载后选择make选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆