0

I was using my own confirm box with the help of kendo window. I displayed two buttons in it and everything is fine. But here comes issue, I want to make any of the button selected by default, so an user can navigate between the buttons.

Note: I don't want to use plugin. Thanks in Advance Regards Varun

4

1 回答 1

0

一个简单的方法,给定以下 HTML:

<form action="#" method="post">
    <button id="button1">Button one</button>
    <button id="button2">Button two</button>
</form>

将会:

var buttons = $('form').find('button');

buttons.eq(Math.floor(
    Math.random() * buttons.length
)).focus();

JS 小提琴演示

参考:

于 2013-05-22T10:35:33.190 回答