使用 jquery 从单击的按钮获取值
我正在构建一个由按钮组成的表单。我想从单击提交按钮时发送到参数的突出显示按钮获取值,但问题是我只找到了一种从单选按钮发送值的方法。有没有等效的方法可以做到这一点?
我知道这仅适用于单选按钮,所以我正在搜索一个等效的查询选择器,它将给出像下面的代码但对于按钮的确切操作
document.querySelector('input[name=customButton]:checked').value
<button type="button" class="btn" id="customButton1" name="customButton" value="1">
<label for="customButton1">Excellent</label>
<button type="button" class="btn" id="customButton2" name="customButton" value="2">
<label for="customButton2">Not good</label>
I'm building a form consisted of button. I want to get value from a highlighted button being sent to a parameter when submit button is clicked, but the problem is I only found a way to sent value from a radio button. Is there any equivalent way to do this?
I know this is only applicable for radio button, so I'm searching an equivalent queryselector that will give exact action like code below but for button
document.querySelector('input[name=customButton]:checked').value
<button type="button" class="btn" id="customButton1" name="customButton" value="1">
<label for="customButton1">Excellent</label>
<button type="button" class="btn" id="customButton2" name="customButton" value="2">
<label for="customButton2">Not good</label>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法像以前那样将单选按钮直接转换为按钮。 HTML 无效
您可以将单选按钮设置为按钮或做这个
You cannot convert a radio directly to a button like you did. The HTML is not valid
You can style a radio like a button or do this