如果选择的按钮少于应有的按钮,则显示警报
我有一个按钮网格,假设用户打开网格并选择按钮“4”,它将在下面显示按钮“A”到“D”(.answerBtns)。现在,如果用户在“答案数量”文本框(#numberAnswerTxt)中输入数字“3”,那么如果用户尝试选择超过 3 个按钮,则会出现一条警告,说明您不能超出限制,取消选择按钮。你可以自己尝试一下。
但我想做的是,假设用户选择较少的按钮,假设用户选择 3 个按钮时只选择 1 个按钮(用户在“答案数”文本框中输入数字 3),我会做什么想要的是,如果用户单击“添加问题”按钮,它应该显示一条警告,提示“选择了最少的按钮,请选择更多的按钮”。该警报应出现在“insertQuestion(this.form)”中。
这怎么能做到呢?
有两个函数可以帮助您,这些是 javascript 代码中的最后两个函数,它们是:
function btnclick(btn)
代码
function insertQuestion(form)
位于 Jsfiddle 中,单击 这里
I have a grid of buttons, lets say user opens up the grid and selects button "4", it will display buttons "A" to "D" below (.answerBtns). Now if user enters in the number "3" in the "Number of Answers" text-box (#numberAnswerTxt), then if the user tries to select more than 3 buttons, it will come up with an alert stating you cannot go beyond limit, deselect a button. You can try this yourself.
But what I want to do is that lets say the user selects less buttons and lets say selects only 1 button when the user is suppose to select 3 buttons (user typed in number 3 in "Number of Answers" text-box), what I want is that if the user clicks on the "Add Question" button, it should display an alert saying "least buttons are selected, please select more buttons". The alert should appear in the "insertQuestion(this.form)".
How can this be done?
There are two functions to look at to help you and these are the last two functions in the javascript code which are:
function btnclick(btn)
and
function insertQuestion(form)
Code is in Jsfiddle, click here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想如果你把它放在 insertQuestion(form) 上它会解决你的问题
i think if you put this on insertQuestion(form) it will solve your problem
试试这个: http://jsfiddle.net/thejase/8fXXR/6/
只是一个想法:禁用该按钮,直到他们可以使用它为止。
Try this: http://jsfiddle.net/thejase/8fXXR/6/
Just a thought: disable the button until they can use it.