给定:
var value = $this.text();
其中value等于: Phasellus pellentesque metus in nulla。真的很好,但我不知道。大叶,大叶,结果是nec,lacinia sed,enim。您的位置:我也知道>教育/教育/培训>教育/服务。
当用户键入: Where value等于: Phasellus pellentesque metus in nulla时。真的很好,但我不知道。大叶,大叶,结果是nec,lacinia sed,enim。您的位置:我也知道>教育/教育>教育/教育
第三个!
我希望JavaScript发出警报,允许我调用不同的函数。
我试着使用:
if (/!!!$/.test(value)) {} but that doesn't seem to be working.
想法?
发布于 2010-07-20 12:33:47
看起来在!!!
之后有一个\n
。使用/m
标志使正则表达式多行。
if (/!!!$/m.test(value)) {
console.log("it works");
}
请检查以下内容:
var s = "When the user tl, sem.The 3 !!!";
if (/!!!$/m.test(s))
console.log("multiline matches"); //prints
if (/!!!$/.test(s))
console.log("single line matches"); //prints
s += "\n";
if (/!!!$/m.test(s))
console.log("multiline matches"); //prints
if (/!!!$/.test(s))
console.log("single line matches"); //doesn't print
发布于 2010-07-20 12:37:08
此代码将说明您的jquery对象转换不正确,请使用以下代码
var value = $(this).text();
发布于 2010-07-20 13:37:12
$this不是指self。$(this)是指self。所以它应该是这样的:
var value = $(this).text();
完整的,例如:
<body>
<p>hello!!!</p>
<p>done</p>
</body>
<script>
$(document).ready( function()
{
$("p").click( function()
{
var value = $(this).text();
if (/!!!$/.test(value)) { msg = 'done';}else{ msg = 'not done';}
alert(msg);
});
});
</script>
https://stackoverflow.com/questions/3287002
复制相似问题