gpt4 book ai didi

确认脚本中的 Javascript IIF

转载 作者:行者123 更新时间:2023-12-03 11:53:57 76 4
gpt4 key购买 nike

在我的服务器端页面上,我有一段旧脚本,我想修改它以在打开确认窗口之前测试字段是否为空。这就是我尝试的方法,添加 $(#hdfldRecId) 因为如果此字段为空,我不希望打开确认。

    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) 中是否有值,如果有则执行确认对话框。

谢谢

最佳答案

return 不是一个方法,所以去掉 ( 和 )。

"return beforeDelete();" 

并且不确定 !> 应该是什么。猜你想检查长度

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

关于确认脚本中的 Javascript IIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25689103/

76 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com