[英]how to get the value returned from the function and use it another function
我正在嘗試使用 javascript 中的正則表達式來創建一個用於清理字段的函數。 這是我的職能。 我的最終目標是獲取一個字符串並對其進行消毒並在某處重復使用。 就像我這個場景我需要字符串
function sani(str){
str = str.replace(/[^a-zA-Z ]/g, "");
return str;
}
$('button').click(function(){
var word = "<h1>Hello W<o>rld";
alert(str);
cleanStr(str);
//I need the following alert to be the string after sanitisation
alert("After sanitisation : "+str)
})
假設您想調用sani
而不是cleanStr
您可以執行以下操作:
function sani(str){
str = str.replace(/[^a-zA-Z ]/g, "");
return str;
}
$('button').click(function(){
var word = "<h1>Hello W<o>rld";
alert(word);
var result = sani(word);
//I need the following alert to be the string after sanitisation
alert("After sanitisation : " + result)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.