日期:2014-05-17  浏览次数:20376 次

后台cs中如何获取前台JS中的值
这个是aspx页面中的代码,我定义了 变量js
<script>  
  function checkDate()  
  {  
  var obj=document.getElementById("Calendar1");  
  var js=false; 
  var temp=obj.value;  
  var pattern=/^(\d{4})-(\d{2})-(\d{2})$/i  
  var matches=temp.match(pattern);  
  if(matches) //匹配 DDDD-DD-DD 的形式  
  {  
  var tempDate=new Date(matches[1],matches[2]-1,matches[3]);  
  if(tempDate.getYear()!=matches[1]||tempDate.getMonth()!=(matches[2]-1)||tempDate.getDate()!=matches[3]) //检查是否正确日期 比如9923-15-48 等形式  
  {  
  alert("日期不正确!");  
  js=true;

  return false; 
  }  
  }  
  else  
  {  
  alert("格式错误");  
  return false;  
  js=true;
  }  
  if(js==true)
  {
  document.getElementById("hid").value=true;
  }
  }  
  </script>  

我想在后台aspx。cs中获取到 js的值
怎么做啊?

能提供详细的解决方案吗 ?关于 隐藏域我没搞懂,不知道怎么做?谁能详细点谢谢!


------解决方案--------------------
if(js==true) 

document.getElementById("hid").value=true; 


=>

document.getElementById("hid").value=js; 

后台取 hid 的vlaue 就可以了
但hid 应该是 <asp:HiddenField