开发中常用js记录(二)

(1)获得asp.net控件的value值

document.getElementById('<%=SUKid.ClientID %>').value

(2)获得选中值

$('#select option:selected').text();

(3)获得选中id 

$('#select option:selected').attr("id");

(4)获得父亲td 的id

$(this).parents('td').attr("id");

(5)Post请求

$.post('@(ViewBag.BasePath)UserCenter/CollectList?page=' +page,
function (data) {
   var json = JSON.parse(data);
    if (json.Status == "ok") {

    } 
  });

(6)相关链接跳转

<a href="javascript:history.go(-1)">返回上一页</a> 

<a href="javascript:location.reload()">刷新当前页面</a> 

<a href="javascript:" onclick="history.go(-2); ">返回前两页</a> 

<a href="javascript:" onclick="self.location=document.referrer;">返回上一页并刷新</a> 

<a href="javascript:" onclick="history.back(); ">返回上一页</a>

(7)改变url参数值并跳转

  function replaceParamVal(paramName, replaceWith) {
  var oUrl = this.location.href.toString();
  var re = eval('/(' + paramName + '=)([^&]*)/gi');
  var nUrl = oUrl.replace(re, paramName + '=' + replaceWith);
  this.location = nUrl;
  }

 

(8)将json字符串转化为json对象

 

   var json = JSON.parse(data);                                                       

posted @ 2016-08-25 10:56  huangenai  阅读(289)  评论(0编辑  收藏  举报