如何将以下代码转换为仅使用jquery库?
<html>
<head>
<script>
function do_it(value)
{
function newXMLHttpRequest()
{
try{ return new XMLHttpRequest(); }catch(e){}
try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){}
try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
return null;
}
var ajax_request = false;
ajax_request = newXMLHttpRequest();
var url = "test.pl?b64="+value;
ajax_request.open("GET",url,1);
ajax_request.onreadystatechange = function()
{
if(ajax_request.readyState == 4)
{
var response = ajax_request.responseText;
document.getElementById("in").innerHTML = response;
}
}
ajax_request.send(null);
}
</script>
</head>
<body>
<form>
<input type="text" name="string" onkeyup="do_it(this.value)"/>
<input type="submit" name="submit">
</form>
<div style="position:absolute;width:200px;height:200px; background-color:yellow; margin-top:100px;" id="in"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
对不起,我可能应该提到我实际上没有任何关于jquery的实践经验,我现在正在熟悉它...
这似乎有些奇怪的问题,但无论如何要点;
我有一个字符串,我需要在几个组合中搜索许多可能的字符出现(所以字符类是不可能的),那么最有效的方法是什么?
我想要把它堆成一个正则表达式:
if ($txt =~ /^(?:really |really |long | regex here)$/){}
Run Code Online (Sandbox Code Playgroud)
或使用几个"较小"的比较,但我认为这不会很有效:
if ($txt =~ /^regex1$/ || $txt =~ /^regex2$/ || $txt =~ /^regex3$/) {}
Run Code Online (Sandbox Code Playgroud)
或者如果比较可能会嵌套几个.
我将不胜感激任何有关此问题的额外建议和其他意见.谢谢