給文本框添加灰色提示文字


html>
<head>
<title>中國站長天空-網頁特效-表單特效-給文本框添加灰色提示文字</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!--把下面代碼加到<body>與</body>之間-->
<input type="text" id="key" name="key" value=" 請輸入關鍵詞" onFocus="if(value==defaultValue){value='';this.style.color='#000'}" onBlur="if(!value){value=defaultValue;this.style.color='#999'}" style="color:#999999">
</body>
</html>

 

在cs后台頁面獲取input的值方法

概述:

      想在后台cs頁面得到前台頁面aspx中html控件input輸入的值.

解決方法如下:

   1.用Request["name"].toString();.

前台代碼如下:

用戶名:<input name="username" type="text">

后台獲取代碼如下(記住:一定要是name的值,不是id的值):

 


string username = Request["username"].ToString();

2.用Request.Form.Get("name").ToString();

前台代碼如上一樣.

后台獲取代碼如下:

 


string username = Request.Form.Get("username").ToString();

3.用Request["name"];

前台代碼如上一樣。

后台獲取代碼如下:

code

string usrname=Request["name"];

 

注:在前台獲取html的值:

方法:document.all.("你的控件的id").value;

 

例如:下面實現了在頁面中搜索的功能

<input id="t1" type="text" />

<input id="Button1" onclick="findInPage(document.all.t1.value)"
            type="button" value="button" />

<script language="javascript">
            var NS4 = (document.layers);var IE4 = (document.all);var win = window;var n = 0;
            function findInPage(str){
             var txt, i, found;
             if (str == '') return false;
             if (NS4){
              if (!win.find(str))
               while(win.find(str, false, true))
               n++;
              else
               n++;
              if (n == 0)
              alert('Not found.');}
             if (IE4){
              txt = win.document.body.createTextRange();
              for (i = 0; i <= n && (found = txt.findText(str)) != false; i++){
               txt.moveStart('character', 1);
               txt.moveEnd('textedit');}
              if (found){
               txt.moveStart('character', -1);
               txt.findText(str);
               txt.select();
               txt.scrollIntoView();
               n++;}else{if (n > 0){
                n = 0;
                findInPage(str);}else alert('沒有符合查詢條件的數據!');}}return false;}
        </script>

這樣就可以實現在頁面中來搜索內容了。呵呵


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM