只是想知道是否有人知道我可以获得表单通知的任何教程或脚本。
我想要的就是当某人在表单中键入特定关键字时,它需要提供一条消息。
我想要做的是当观众在表格中输入以下关键词时;
Medlab Central
Medlab Wanganui
Naylor Lawrence
Doughboys Bakery Limited – owners surname ‘Funke’
Denver Stockfeeds Limited – owners surname ‘Currie’
Midland Civil Limited – Miles and Vicky Worsley
Arran Trust – Stephen and Mary Barr
Roadmarking Services Limited – Karen and Kelly halligan
Steeds Pharmacy Ltd
我想要弹出一个通知,说'可能存在利益冲突。请等一下Proa,了解他们如何提供帮助'
快点,这是HTML的正确编码;
<form id="theForm">
<input type="text" />
<input type="submit" value="Send Email">
</form>
</body>
<script>
var specialWords = ["hello", "goodbye"];
$(function(){
$('#theForm').on("change keyup", "input[type='text']", function(event){
var inputValue = $(this).val();
if($.inArray(inputValue, specialWords) > -1){
alert(inputValue + " is a special word!");
}
});
});
</script>
</html>
我找到了一个有效的脚本..
<script language="JavaScript">
var nav=navigator.appName;
var ns=(nav.indexOf("Netscape")!=-1);
if(ns){
if(document.layers){
document.captureEvents(Event.KEYPRESS);
document.onkeypress = cheat;
}
if(document.getElementById){
document.onkeypress = cheat;
}
}
else
{document.onkeypress = cheat;}
var SpecialWords = "here"
var SpecialLetter = 0;
var vcheat = false
function cheat(keyStroke)
{
var eventChooser = (ns)?keyStroke.which: event.keyCode;
var which = String.fromCharCode(eventChooser).toLowerCase();
if(which == SpecialWord.charAt(SpecialLetter)){
SpecialLetter++;
if (SpecialLetter == SpecialWord.length) alert("There may be a conflict of interest. Please wait to hear from PROA regarding how they can help")
}
else {SpecialLetter = 0;vcheat = false}
}
</script>
但是我现在需要它来处理多个特殊字。我试着做Mark所说的那个
var specialWords = ["hello", "goodbye"];
但不会工作。任何建议。
答案 0 :(得分:1)
正如你标记了jquery,我会假设像jquery validate这样的插件
http://archive.plugins.jquery.com/project/validate
演示包含在页面底部。
答案 1 :(得分:1)
标准Javascript弹出窗口的一个很好的资源是:http://www.w3schools.com/js/js_popup.asp。有些人不喜欢它们,因为你不能对它们应用自定义样式并且是同步的(浏览器在删除弹出窗口之前不能做任何事情)但是它们易于使用并且引起了用户的注意! / p>
我不确定你想要什么,但下面的示例代码可能有帮助 - 当用户在文本字段中键入“hello”或“goodbye”时它会触发警报(只需更改数组根据需要!)。这里我假设标记包含以下内容:
<form id="theForm">
<input type="text" />
</form>
然后以下jquery代码应该这样做:
var specialWords = ["hello", "goodbye"];
$(function(){
$('#theForm').on("change keyup", "input[type='text']", function(event){
var inputValue = $(this).val();
if($.inArray(inputValue, specialWords) > -1){
alert("There may be a conflict of interest...");
}
});
});