html---文本框樣式;


一、一個單行文本框的例子

<form name="form1" action="mailto:3400982550@qq.com" method="post" enctype="text/plain">
<p>您的姓名: <input type="text" name="text1" size="12" maxlength="20">
您的E_mail: <input type="text" name="text2" size="20" maxlength="24" value="*****@*.*">
輸入口令: <input type="password" name="text3" size="8" maxlength="8"> </p>
<p align="center"> 
<input type="submit" name="提交" value="提 交">
<input type="reset" name="重寫" value="重 寫">
</p>
</form>

二、檢驗用戶輸入的信息

<script language="javascript">
<!--
function test(form){
test1(form);
test2(form);
test3(form)}
function test1(form){
if (form.text1.value=="")
alert("你沒有寫上你的姓名,請輸入姓名!")
}
function test2(form){
if (form.text2.value==""||form.text2.value.indexOf('@',0)==-1)
alert("E_mail地址不正確,請重新輸入!")
}
function test3(form){
if (form.text3.value!="12345678")
alert("密碼錯誤,請重新輸入!")
}
-->
</script>

三、制作一個留言簿

<form name="form2" action="mailto:fyy0528@sina.com" method="post" enctype="text/plain" >
<table width="50%" border="1" bordercolorlight="#000000" bordercolordark="#FFFFFF" bgcolor="#CCFFCC" cellpadding="4" align="left">
<tr> 
<td colspan="2"> <div align="center"><b>留 言 簿</b></div> </td>
</tr>
<tr> 
<td>姓名: <input type="text" name="textfield" size="8"> </td>
<td>E_mail: <input type="text" name="textfield2" size="10" maxlength="20"> </td>
</tr>
<tr> 
<td colspan="2"> <div align="center">留 言<br> <textarea name="textfield3" cols="30" rows="3"></textarea>
</div>
</td>
</tr>
<tr> 
<td> <div align="right"> <input type="submit" name="Submit" value="提 交"> </div> </td>
<td> <input type="reset" name="Submit2" value="重 寫"> </td>
</tr>
</table>
</form>

html文本框參考樣式

輸入框景背景透明:

<input style="background:transparent;border:1px solid #ffffff">

 

 

 

鼠標划過輸入框,輸入框背景色變色:

<INPUT value="Type here" NAME="user_pass" TYPE="text" SIZE="29" onmouseover="this.style.borderColor='black';this.style.backgroundColor='plum'"
style="width: 106; height: 21"
onmouseout="this.style.borderColor='black';this.style.backgroundColor='#ffffff'" style="border-width:1px;border-color=black">

 

 

輸入字時輸入框邊框閃爍(邊框為小方型):

<Script Language="JavaScript">
function borderColor(){
if(self['oText'].style.borderColor=='red'){
self['oText'].style.borderColor = 'yellow';
}else{
self['oText'].style.borderColor = 'red';
}
oTime = setTimeout('borderColor()',400);
}
</Script>
<input type="text" id="oText" style="border:5px dotted red;color:red" onfocus="borderColor(this);" onblur="clearTimeout(oTime);">

 

 

 

輸入字時輸入框邊框閃爍(邊框為虛線):

<style>
#oText{border:1px dotted #ff0000;ryo:expression_r(onfocus=function light (){with(document.all.oText){style.borderColor=(style.borderColor=="#ffee00"?"#ff0000":"#ffee00");timer=setTimeout(light,500);}},onblur=function(){this.style.borderColor="#ff0000";clearTimeout(timer)})};
</style>
<input type="text" id="oText">
 

 

自動橫向廷伸的輸入框:

<input type="text" style="huerreson:expression_r(this.width=this.scrollWidth)" value="abcdefghijk">

 

 

 

自動向下廷伸的文本框:

<textarea name="content" rows="6" cols="80" onpropertychange="if(this.scrollHeight>80) this.style.posHeight=this.scrollHeight+5">輸入幾個回車試試</textarea>

 

 

只有下划線的文本框:

<input style="border:0;border-bottom:1 solid black;background:;">

 

 

 


html文本框常見操作技巧

1、html文本框怎么用css變圓角
 

border-radius屬性可以實現元素的圓角。如下css可以實現文本框(單行、多行)的圓角:
input[type=text],textarea{border-radius:3px;border:1px solid #000;}

border-radius用法如下:
border-radius 屬性是一個簡寫屬性,用於設置四個 border-*-radius 屬性。
該屬性允許為元素添加圓角邊框
語法:

border-radius: 1-4 length|% / 1-4 length|%;

按此順序設置每個 radius 的四個值。
如果省略 bottom-left,則與 top-right 相同。
如果省略 bottom-right,則與 top-left 相同。
如果省略 top-right,則與 top-left 相同。
單位一般用px和百分比較多,其他單位也可

 

 

 

2、HTML中如何設置文本框的大小

邊框的大小,可以使用CSS樣式控制,如:
<textarea id="txtCon" >content</textarea>
<style type="text/css">
#txtCon{width:100px; height:20px;}
</style>

也可以使用文本框自己的屬性,定義文本框的行和列控制大小,如:
<textarea id="txtCon" rows="100" cols="100" >content</textarea>

 

3、在html中如何實現將本網頁中文本框中的值傳遞到另一個網頁的用戶名密碼框中,並實現登陸

在html網頁中,一個按鈕,兩個文本框,在<SCRIPT language=JavaScript> /SCRIPT>當中如何寫代碼能夠實現將這兩個文本框中的值傳遞到另一個制定地址的網頁中的用戶名和密碼處,並實現登陸?

 

頁面必須是跳轉過去的才行。例如另一個頁面是page.html那么你跳轉的時候 page.html?username=tony&password=123 跳轉到這個地址,

然后到另一個頁面的時候在腳本里面寫
<SCRIPT language=JavaScript>
var url = window.location.href;
然后var username = url.split("?")[1].split("&")[0].split("=")[1] //這樣就獲取到用戶名了。
var password = url.split("&")[1].split("=")[1];

然后把值賦給你的密碼文本框
document.getElementById("txtpassword").value = password;
document.getElementById("txtusername").value=username;
< /SCRIPT>

然后驗證用戶名和密碼就可以了。

 

 

4、HTML中讓表單input等文本框為只讀不可編輯的方法

有時候,我們希望表單中的文本框是只讀的,讓用戶不能修改其中的信息,如使<input type="text" name="input1" value="中國"> 的內容,"中國"兩個字不可以修改。實現的方式歸納一下,有如下幾種。 

方法1: onfocus=this.blur() 當鼠標放不上就離開焦點
<input type="text" name="input1" value="中國" onfocus=this.blur()> 

方法2:readonly 
<input type="text" name="input1" value="中國" readonly> 
<input type="text" name="input1" value="中國" readonly="true"> 

方法3: disabled 
<input type="text" name="input1" value="中國" disabled="true">

完整的例子:

<input name="ly_qq" type="text" tabindex="2" onMouseOver="this.className='input_1'" onMouseOut="this.className='input_2'" value="123456789" disabled="true" readOnly="true" /> 

disabled="true" 此果文字會變成灰色,不可編輯。 
readOnly="true" 文字不會變色,也是不可編輯的

css屏蔽輸入:<input style="ime-mode: disabled"> 

有兩種方法第一:disabled="disabled"這樣定義之后被禁用的 input 元素既不可用,也不可點擊。第二:readonly="readonly" 只讀字段是不能修改的。不過,用戶仍然可以使用 tab 鍵切換到該字段,還可以選中或拷貝其文本;

 


免責聲明!

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



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