我的.js文件位于index.html的单独文件夹中
以下是buildit.js的内容
//On change event for the textbox plate text
function setValue(target){
var platetext = target.value;
$('#numberplateyellow').empty();
$('#numberplatewhite').empty();
var plateregex=/^[A-Za-z]{2}[ ]{0,1}[0-9]{2}[ ]{0,1}[a-zA-Z]{3}$/
if (document.platebuilder.target.value.search(plateregex)==-1){
var answer = confirm ("Non LEGAL Plate Detected (YES WE WILL SHOW THE AGREE BOX ONCE I HAVE IT FROM TOM) \n\n Do you understand that this is now classed as a show plate ?");
if (answer) {
$('#numberplateyellow').append(platetext);
$('#numberplatewhite').append(platetext);
}
}
}
这些是在输入框中的onchange上调用的,你能解释为什么没有显示警告框吗?如果你有机会在每个字母输入后都可以.append吗?
亲切的问候
答案 0 :(得分:0)
因为你要传入一个你想要引用它的函数而没有“document.platebuilder”
当有人改变输入字段的内容时,我不清楚你想看到什么?
function setValue(target)
{
var platetext = target.value;
$('#numberplateyellow').empty();
$('#numberplatewhite').empty();
var plateregex=/^[A-Za-z]{2}[ ]{0,1}[0-9]{2}[ ]{0,1}[a-zA-Z]{3}$/
if (target.value.search(plateregex)==-1)
{
var answer = "Non LEGAL Plate Detected (YES WE WILL SHOW THE AGREE BOX ONCE I HAVE IT FROM TOM) \n\n Do you understand that this is now classed as a show plate ?";
alert(answer);
$('#numberplateyellow').append(platetext);
$('#numberplatewhite').append(platetext);
}
}
如果你想为按下的每个键运行它,那么你需要将其设置为在keypressed事件而不是onchange上运行(但是由于警报,这会非常烦人...)