gpt4 book ai didi

c# - 确认框javascript

转载 作者:行者123 更新时间:2023-11-28 16:25:33 27 4
gpt4 key购买 nike

问题:

每当我单击“保存”按钮时,都会弹出一个确认框。当我单击“确定”时,它可以很好地保存数据。但是当我单击“取消”时,它不会取消更改。相反,它拯救了他们。您能帮我解决这个问题吗:

这是它的 JavaScript:

/
<asp:Button ID="view_btn_save" Text="Save" ValidationGroup="view" OnClick="view_btn_save_click"
OnClientClick="Validate_view()" runat="server"
/>
</td>
<script type="text/javascript">
function Validate_view() {
var value = document.getElementById('<%=view_txt_name.ClientID%>').value;
var value2 = document.getElementById('<%=view_txt_title.ClientID%>').value;
var value3 = document.getElementById('<%=view_txt_description.ClientID%>').value;
var value4 = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
var value5 = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;

if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
return alert('Please enter the missing fields');
}
else {
return confirm('Confirm changes?');
}
}

最佳答案

您需要将 return 语句添加到 OnClientClick 声明中:

OnClientClick="return Validate_view();"

如果您显示警报,我会将您的代码更改为:

alert("...");
return false;

编辑:这是一个完整的示例

<script type="text/javascript"> 
function Validate_view() {
var value = document.getElementById('<%=view_txt_name.ClientID%>').value;
var value2 = document.getElementById('<%=view_txt_title.ClientID%>').value;
var value3 = document.getElementById('<%=view_txt_description.ClientID%>').value;
var value4 = document.getElementById('<%=view_txt_pixelwidth.ClientID%>').value;
var value5 = document.getElementById('<%=view_txt_pixelheight.ClientID%>').value;

if (value == '' || value2 == '' || value3 == '' || value4 == '' || value5 == '') {
alert('Please enter the missing fields');
return false;
}
else {
return confirm('Confirm changes?');
}
}
</script>
<asp:Button ID="view_btn_save" runat="server" Text="Save" OnClientClick="return Validate_view()" OnClick="view_btn_save_click" />

关于c# - 确认框javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8170859/

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