本文介绍了用于确认功能的Java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用确认功能是js并在点击按钮时调用该功能,我点击按钮中的按钮时显示确认框,但是我在确认功能中传递的消息是没有出现。这是下面的代码 < script type =text / javascript> function confirm(){ var x; var r = confirm(' 你是吗?肯定)!; if (r == true ) {x = 你按OK!; } 其他 {x = 你按下取消!; } 我在这里传递消息你确定但是我没有得到它,而是它是空白的我是什么我得到的只是两个按钮,是好的&取消。 < asp:GridView ID = gdvData runat = server 高度 = 159px 宽度 = 511px AutoGenerateColumns = 错误 > < 列 > < asp:TemplateField HeaderText =删除HeaderStyle-BackColor =#4EA600Head erStyle-ForeColor =White> < itemtemplate> < asp:LinkBut​​ton ID =ButtonDeleteText =DeleteOnClientClick =confirm() 价值=你确定! runat =server/> 还请告诉我如何使用按钮的onclick事件,即OK和取消确认功能解决方案 hi, 试试改变如下: < asp:linkbutton id =ButtonDeletetext =Deleteonclientclick =return confirmmessage(); value =你确定! runat =server/> < script> function confirmmessage() { if (确认(' 你确定!')) { // 是 // 在编码方调用你的sp .ajax({ type: POST, url: Demo.aspx / DeleteSupplierDetails, contentType: application / json; charset = utf-8, data: {R1:' + value + ',R2:' + Value + ',R3:' + Value + ',R4:' + Value + '}, dataType: json, 成功:功能(数据){ 如果(data.d == true ) alert(' 成功调用sp ); },失败: function (数据){ alert(' sp不称为); } }); } 其他 { // 否 返回 false ; } } < / script> //服务器端 [System.Web.Services.WebMethod(true)] public static bool DeleteSupplierDetails(string R1,string R2,string R3,string R4) { // call你的sp //如果成功返回true; } 希望它有所帮助。 看到这个...... :) < html > < head > < script > function disp_confirm() { var r = confirm( 按a按钮!) 如果(r == true ) { alert( 你按下OK!)} else { alert( 你按下取消!)} } < / script > < / head > < body > < 输入 type = 按钮 onclick = disp_confirm() value = 显示确认框 > ; < / body > < / html > I am using a confirm function is js and calling the function on the click of a button, i am getting the Confirm box on the click of the button in the button, but the message that i am passing in the Confirm function is not appearing.Here is the code below<script type="text/javascript">function confirm() { var x; var r=confirm('Are You Sure!'); if (r==true) { x="You pressed OK!"; } else { x="You pressed Cancel!"; }I am passing a message here Are you sure but i m not getting it, rather it is blank and what i am getting is only the two buttons that is OK & Cancel.<asp:GridView ID="gdvData" runat="server" Height="159px" Width="511px" AutoGenerateColumns="False"> <Columns> <asp:TemplateField HeaderText="Delete" HeaderStyle-BackColor="#4EA600" HeaderStyle-ForeColor="White"> <itemtemplate> <asp:LinkButton ID ="ButtonDelete" Text="Delete" OnClientClick="confirm()" value="Are You Sure!" runat="server" /> And also please let me know how can i use the onclick event of the Buttons i.e. Ok and Cancel of the Confirm function 解决方案 hi, try to change like below:<asp:linkbutton id="ButtonDelete" text="Delete" onclientclick="return confirmmessage();" value="Are You Sure!" runat="server" /><script> function confirmmessage() { if(confirm('Are you sure!')) { //yes // to call your sp on coding side.ajax({ type: "POST", url: "Demo.aspx/DeleteSupplierDetails", contentType: "application/json; charset=utf-8", data: "{R1:'" + value+ "', R2:'" + Value+ "', R3:'" + Value+ "', R4:'" + Value + "'}", dataType: "json", success: function (data) { if(data.d == true) alert('successfully call sp'); }, failure: function (data) { alert('sp not called'); } }); } else { //No return false; } }</script>// on server side[System.Web.Services.WebMethod(true)] public static bool DeleteSupplierDetails(string R1,string R2,string R3,string R4) { //call your sp // if success return true; }hope it helps.see this...:)<html><head><script>function disp_confirm(){var r=confirm("Press a button!")if (r==true) { alert("You pressed OK!") }else { alert("You pressed Cancel!") }}</script></head><body><input type="button" onclick="disp_confirm()" value="Display a confirm box"></body></html> 这篇关于用于确认功能的Java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-18 22:54