您的位置:首页 > Web前端 > JavaScript

117 js option跳转 获取option内的text

2015-11-24 16:48 387 查看
<select name="here" onchange="location.href= '__URL__/index/orgno/'+this.options[this.selectedIndex].value;" class="ui-panel-head-more fr" id="orgno-handle">
<option value="2" <if condition="$_GET['orgno'] eq '1' ">selected</if>  >xx局</option>
<option value="1" <if condition="$_GET['orgno'] eq '2' ">selected</if> >xx中心</option>
</select>

option跳转

$("#leaderuserid").change(function(){
var obj = document.getElementById("leaderuserid");
var txt = obj.options[obj.selectedIndex].text;
document.getElementById("leadername").value= txt;
});
获取option内的text

$('#leaderuserid>option:selected').text();


另一种跳转方法

$("#orgselect").change(function(){
var orgno = $(this).val();
var old_orgno = getQueryString("orgno");
if(old_orgno){
window.location.href = CURL.replace(old_orgno,orgno);
}else{
window.location.href = CURL+"&orgno="+orgno;
}
});


此处需要用到工具函数 getQeuryString

function getQueryString(name){

var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)
return  unescape(r[2]);

return null;
}

这个正则是寻找&+url参数名字=值+&
&可以不存在。

([^&]*)  [^&]表示匹配不包含&的内容 *表示可以重复0或N次
(&|$)" 表示跟在前面匹配到的字符后面必须是&"或$"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: