- 1、js代碼怎麼寫
- 2、js實現點擊輸入用戶名或密碼的文本框在旁邊彈出提示語
- 3、input 如果沒有輸入或者輸入空字元 ,就提示不能為空.的JS 代碼
- 4、用javascript實現頁面中彈出一個輸入提示框,讀取一個輸入 英文字元或一個數字或一個漢字
- 5、js信息輸錯後輸入框後提示紅字代碼如何編寫
建議樓主看下js基礎
每一項都是js使用中的小技巧,基礎但十分的實用!
1.document.write(“”); 輸出語句
2.JS中的注釋為//
3.傳統的HTML文檔順序是:
document-html-(head,body)
4.一個瀏覽器窗口中的DOM順序是:
window-(navigator,screen,history,location,document)
5.得到表單中元素的名稱和值:
document.getElementById(“表單中元素的ID號”).name(或value)
6.一個小寫轉大寫的JS:
document.getElementById(“output”).value=document.getElementById(“input”).value.toUpperCase();
7.JS中的值類型:
String,Number,Boolean,Null,Object,Function
8.JS中的字元型轉換成數值型:
parseInt(),parseFloat()
9.JS中的數字轉換成字元型:
(“” 變數)
10.JS中的取字元串長度是:
(length)
11.JS中的字元與字元相連接使用 號.
12.JS中的比較操作符有:
==等於,!=不等於,,=,.=
13.JS中聲明變數使用:
var來進行聲明
14.JS中的判斷語句結構:
if(condition){}else{}
15.JS中的循環結構:
for([initial expression];[condition];[upadte expression]) {inside loop}
16.循環中止的命令是:
break
17.JS中的函數定義:
function functionName([parameter],…){statement[s]}
18.當文件中出現多個form表單時.可以用document.forms[0],document.forms[1]來代替.
19.窗口:
打開窗口window.open(), 關閉一個窗口:window.close(), 窗口本身:self
20.狀態欄的設置:
window.status=”字元”;
21.彈出提示信息:
window.alert(“字元”);
22.彈出確認框:
window.confirm();
23.彈出輸入提示框:
window.prompt();
24.指定當前顯示鏈接的位置:
window.location.href=”URL”
25.取出窗體中的所有表單的數量:
document.forms.length
26.關閉文檔的輸出流:
document.close();
27.字元串追加連接符: =
28.創建一個文檔元素:
document.createElement(),document.createTextNode()
29.得到元素的方法:
document.getElementById()
30.設置表單中所有文本型的成員的值為空:
var form = window.document.forms[0]
for (var i = 0; iform.elements.length;i ){
if (form.elements.type == “text”){
form.elements.value = “”;
}
}
你可以使用formValidator.js,專門做表單驗證的,效果如下:
用法很簡單,引用formValidator.js的核心類庫,然後初始化$.formValidator.initConfig({formid: “main”,debug:false,submitOnce : true});
然後對要做校驗的文本框編寫校驗代碼
$(“#employeeNo”).formValidator({onshow : “輸入範圍為1到10個字元”,
onfocus : “輸入範圍為1到10個字元”,oncorrect : ” “}).inputValidator({
min: 1, max: 10, empty:{leftempty:false,rightempty:false,emptyerror:”該欄位左右不允許出現空格”}, onerror : “輸入範圍為1到10個字元”});
$(“#employeeName”).formValidator({onshow : “輸入範圍為1到40個字元”,
onfocus : “輸入範圍為1到40個字元”,oncorrect : ” “}).inputValidator({
min: 1, max: 40, empty:{leftempty:false,rightempty:false,emptyerror:”該欄位左右不允許出現空格”}, onerror : “輸入範圍為1到40個字元”});
在後面對應的div id=”employeeNoTip”/div顯示提示語
formValidator.js這個網上有很多實例和教程,很簡單的
input type=”text” name=”” value=”” onblur=”javascript:if(this.value==”||this.value==’ ‘){alert(‘不為空’);}” /
根據你的要求,我寫了以下示例代碼:
var inputChar = prompt(“隨便輸入一個英文字元、數字或漢字”,””);
inputChar = inputChar.substr(0,1); //只取第一個字元,後面的拋棄
if(inputChar.match(/[a-z]/gi)){
console.log(“英文字元”);
}
if(inputChar.match(/[0-9]/gi)){
console.log(“一個數字”);
}
if(inputChar.match(/[\u4e00-\u9fa5]/gi)){
console.log(“一個漢字”);
}
希望能幫到你~
需要準備的材料分別有:電腦、html編輯器、瀏覽器。
1、首先,打開html編輯器,新建html文件,例如:index.html。
2、在index.html中的script標籤,輸入js代碼:
error();
function error() {
$(‘input’).after(‘span style=”color:red”用戶名不存在/span’);
}
3、瀏覽器運行index.html頁面,此時輸入框後面會顯示出紅色錯誤提示。
原創文章,作者:HEUHE,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/126546.html