×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

这是一个例程,可以实现你要求的功能,记住要让ToolBar打开PopUp功能,因为它会弹出Confirm窗口

<html>
<head>
<script type="text/javascript">
var index
function remember()
{
index=document.form1.Select1.selectedIndex;
}

function change()
{
var sure=confirm("Sure");
if(sure==false)
{
document.form1.Select1.selectedIndex=index;
}
}
</script>
</head>
<body>
<form name="form1" id="form1">
<select id="Select1" style="width: 98px" onmousedown="remember()" onchange="change()">
<option value="001" selected >001</option>
<option value="002">002</option>
<option value="003">003</option>
<option value="004">004</option>
<option value="005">005</option>
</select>
</form>
</body>
</html>
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / a dropdown list, onchange event, show confirmation box. is there a way to keep the original selectedIndex instead of the new selectedIndex when "cancel" is chosen?Thanks
    javascript help please: a dropdown list, before the user chose another item in the list, show confirmation on impact of the change and choice of "continue" or "cancel". is there a way to keep the original selectedIndex instead of the new selectedIndex when "cancel" is chosen?
    • not for ie, but possible if you are using mozilla firefox
    • Yes, you can, put a hidden input box on the page, and assign original value on it. After visitor confirmed, change it to new value.
    • 用 onmousedown=func() 来判断,点击鼠标的时候记住dropdownlist的值,选择cancel的时候再恢复这个值
      • this one I tried, didn't work
    • 这是一个例程,可以实现你要求的功能,记住要让ToolBar打开PopUp功能,因为它会弹出Confirm窗口
      <html>
      <head>
      <script type="text/javascript">
      var index
      function remember()
      {
      index=document.form1.Select1.selectedIndex;
      }

      function change()
      {
      var sure=confirm("Sure");
      if(sure==false)
      {
      document.form1.Select1.selectedIndex=index;
      }
      }
      </script>
      </head>
      <body>
      <form name="form1" id="form1">
      <select id="Select1" style="width: 98px" onmousedown="remember()" onchange="change()">
      <option value="001" selected >001</option>
      <option value="002">002</option>
      <option value="003">003</option>
      <option value="004">004</option>
      <option value="005">005</option>
      </select>
      </form>
      </body>
      </html>
      • it works perfectly, thanks. by the way, do you know if it is possible to change the lables of the confirm buttons, e.g. "Proceed" instead of "OK"?
        • <INPUT TYPE='submit' value='Proceed'>
        • 我想楼主的意思是:在执行函数Confirm("xxx);时候会弹出带有“OK”和“Cancel”按钮的对话框,楼主想把这个对话框两面的两个按钮的文字改变,比如把“OK”改成“FLG”,呵呵,我是觉得不可能
          • That is what I meant. seems I have to live with "OK", instead of "FLG".
          • ^_^ :D
      • No, I don't think u can do it in JavaScript, but in VBScript there is a MsgBox() might acheive what u want, but VBScript can only run under IE,,.....
        • I don't believe in client side scripting, there are something that you can do with VBScript but not JavaScript.
        • 在VBScript中有个MsgBox()函数可以弹出个性化的对话框,大概是本人才疏学浅,至今尚未发现JScript中有相应类似函数
          • Google.
            • That's different, the point is "个性化的对话框"
              • It's the same as msgbox.
                • No, they are totally different. CONFIRM can only creates a popup box with an OK and CANCEL choice, that's it. but msgbox can do much more, check this link about msgbox
    • thanks everyone, I will give it a try tomorrow and let you know.
    • 浏览器因为出于安全方面的考虑,做了很多限制,不让Script程序控制很多资源,比如打印,只能用window.print()打印整个页面,没有进一步的控制细节能力(无法删掉页眉页脚)