我想创建一个小程序来检查输入字段中是否有任何文本...如果它是一个数字,那么我只是这样做
cardsp.value >= 1
但是当输入是文本时,我如何检查字段中是否有任何内容?
Name : <input id="namep" type="text" />
我尝试做类似的事情(js),但这可能是某人做过的最错误的方式
var array= ["","a","b","c","d","e","f","g","h","i","j","k","m","n","l","o","p","q","r","s","t","u","v","w","x","y","z"];
function pay() {
namep.value
if(namep.value >= array.indexOf("a"), cardsp.value >= 1 , emailpa.value >= 1){
alert('Ty For Buying a Ticket From our compeny , you will receive the Invoicing in the ' +emailpa.value);
}
else if(namep.value == array.indexOf(""){
alert('Please Write Your Name');
}
}
答案 0 :(得分:1)
您可以检查输入字段是否只包含字母:
var letters = /^[a-z]+$/;
if( namep.value.match(letters) ) {
// string contains only letters.
}
答案 1 :(得分:0)
var input=$("#namep").val();
或
var input = document.getElementById('namep').value;
然后检查是否有什么......
if(input.length>0)
{
//do something.
}
或
var inputLength = input.length;
if(inputLength>0)
{
//do something.
}