2012-02-01 84 views
0

想知道是否有人知道任何教程或腳本可以獲取表單通知。用於HTML的通知警報消息

我想要的是當某人在表單中鍵入特定關鍵字時,它需要提供一條消息。

我想要做的是當查看器將以下關鍵字輸入到表單中時;

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> 

但是我現在需要爲多個specialwords工作。我試圖做什麼馬克說這是

var specialWords = ["hello", "goodbye"]; 

但不會工作。有什麼建議麼。

+1

請明確你的問題。你想要什麼信息?你想做什麼? – AlphaMale 2012-02-01 06:11:21

+0

難道你不能只使用上面的jquery代碼(從我的答案)並更改獲取警報的值和'specialWords'數組?下面的代碼似乎沒有增加任何內容 - 事實上它在某些情況下不起作用 - 例如用戶右鍵點擊粘貼東西,或者有兩個輸入框等。 – 2012-02-03 08:36:14

回答

1

標準Javascript彈出窗口的一個很好的資源是:http://www.w3schools.com/js/js_popup.asp。有些人不喜歡他們,因爲你無法將自定義樣式應用於他們,並且是同步的(瀏覽器在彈出窗口被刪除之前不能做任何事情),但它們使用起來很簡單,並且獲得用戶的關注!

我不確定你想要什麼,但下面的示例代碼可能有幫助 - 當用戶在文本字段中鍵入「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..."); 
     } 
    }); 
}); 

編輯:注意,jQuery的on功能是作爲1.7版本,如果您使用的是舊版本,請嘗試查看livedelegate