2010-07-20 115 views
0

考慮:的Photoshop - 如果該元素的當前值與!!!結束,觸發警報

var value = $this.text(); 

值等於其中:南營養恐懼可言。性能目前巧克力醬。 Morbi ERAT turpis,lobortis中,consequat NEC,lacinia sed的,例如。聊天的玩家機場,氫氣和可抵扣的,醬或沙拉。

當用戶鍵入:凡值相等,在南營養沒有恐懼。性能目前巧克力醬。 Morbi ERAT turpis,lobortis中,consequat NEC,lacinia sed的,例如。聊天的玩家機場,氫氣和可抵扣的,醬或沙拉。!!!

3!

1的JavaScript要提醒,讓我打電話給不同的功能。

1'm嘗試使用

if (/!!!$/.test(value)) {} but that doesn't seem to be working. 

想法?

+1

這應該工作。 1'm有點擔心this.text'$()'真的包含了你所期望的價值? – 2010-07-20 04:27:34

+0

原來這需要修剪? thxs – WozPoz 2010-07-20 04:35:04

回答

1

它看起來像有是!!!\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 
0

此代碼將你的工作筆記轉換爲jQuery對象是不正確的,請使用以下

var value = $(this).text(); 
0

$但這是指自我。 $(這)是指自我。所以它應該是這樣的:

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>