2014-09-05 141 views
0

在我的服務器端頁面上,我有一段遺留腳本,我想修改它以測試在打開確認窗口之前字段是否爲空。這是我嘗試添加$(#hdfldRecId),因爲如果此字段爲空,我不希望打開確認。確認腳本中的Java腳本IIF

scriptBlock = "function beforeDelete()" & vbCrLf & _ 
         "{return($('#hdfldRecId').val() !> '' && confirm('Are you sure you want to delete this item?'));}" 
If (Not ClientScript.IsClientScriptBlockRegistered("deletePromptScript")) Then 
      ClientScript.RegisterClientScriptBlock(Me.GetType(), _ 
                "deletePromptScript", _ 
                scriptBlock, _ 
                True) 
End If 

    'use the OnClientClick property of the button to cause the above 
    'script to be executed when the button is clicked 

btndelete.OnClientClick = "return(beforeDelete());" 

當我執行頁面時,調試表明()缺少,但配對都匹配。

<script type="text/javascript"> 
//<![CDATA[ 
function beforeDelete() 
{return($('#hdfldRecId').val() !> '' && confirm('Are you sure you want to delete this item?'));}//]]> 
</script> 

所以我不知道我怎麼添加這個測試,看看是否有在$(hdfldRecId)的值,如果有則執行確認對話框。

謝謝

+0

返回不是一個方法,所以擺脫(和)。 ''return beforeDelete();「' – epascarello 2014-09-05 15:22:19

+1

什麼是'!>' – epascarello 2014-09-05 15:23:06

+0

我在」vbCrLf&「之後看到了一些」_「這是什麼? – patricK 2014-09-05 15:27:42

回答

1

返回不是一個方法,所以擺脫(和)。

"return beforeDelete();" 

並不確定什麼!>應該是。猜測你要檢查的長度

function beforeDelete() { 
    return $('#hdfldRecId').val().length && confirm('Are you sure you want to delete this item?'); 
} 
+0

謝謝,這似乎工作 – 2014-09-05 15:42:15

0

你試過:

btndelete.OnClientClick = "beforeDelete;" 

或者確實:

btndelete.OnClientClick = "return beforeDelete();" 

除了修復該epascarello指出了這個錯誤。