Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

jquery - JavaScript: How to select "Cancel" by default in confirm box?

I am displaying a JavaScript confirm box when the user clicks on the "Delete Data" button. I am displaying it as shown in this image:

alt text

In the image, the "OK" button is selected by default. I want to select the "Cancel" button by default, so that if the user accidentally presses the enter key, the records will be safe and will not be deleted.

Is there any way in JavaScript to select the "Cancel" button by default?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't do that, but you could use/write your own dialog which is displayed using DOM elements (like phoenix suggested, it just doesn't have to be that particular jQuery plugin, you could write your own or use plugin from another JS framework).

The "use jQuery + plugin X" answers are starting to get annoying. There are a lot of JS libraries out there and even more plugins. For example using any JS library here is unnecessary if you just want to display a custom dialog. While it's a quick solution/answer, answers like that do more harm in a long run then good. People new to JavaScript or programing in general start to think that jQuery and/or plugins are the only way to go and they include 50kb+ library just to write 3 lines of their own (which sometimes don't even use the library :D).

In my opinion Markus Johnsson comment is the best answer, it's a shame it's not posted as one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...