gpt4 book ai didi

Javascript将单选按钮添加到DOM中的对话框

转载 作者:行者123 更新时间:2023-11-30 12:38:07 28 4
gpt4 key购买 nike

我对使用 DOM 很陌生,我在使用单选按钮时遇到了麻烦。我有一个图像按钮,单击该按钮会打开一个对话框,其中包含“确定”和“取消”选项。我想要做的是将 2 个单选按钮(ASC 和 DESC)添加到位于文本下方和 OK 和 Cancel 按钮上方的对话框中。这能做到吗?

我目前拥有的:

function changeTheFilter(){

if (confirm("How would you like to filter the column?") == true) {
x = "OK";
alert("Get the result of the radio button");
} else {
x = "Cancel";
alert("Keep everything the same");
}
}

显示:

enter image description here


我知道要创建一个单选按钮我可以使用:

 var x = document.createElement("INPUT");
x.setAttribute("type", "radio");
x.setAttribute("id","filter");
x.setAttribute("value","ASC");
document.body.appendChild(x);

但我遇到了麻烦:

  1. 将单选按钮添加到对话框中。

  2. 将单选按钮放在测试下方和按钮上方。

  3. 识别点击了哪个按钮。


先谢谢了!!!如果我不清楚,请告诉我,我很乐意解释。

最佳答案

很遗憾,alert() 框和prompt()confirm() 无法修改。但是既然你问是否可以使用 JQuery 来实现这一点,我建议你使用 JQuery UI 对话框:

http://jqueryui.com/dialog/

$('#mydialogID').dialog({//put dialog option here});

您可以在上面提供的链接中找到上述选项。

关于Javascript将单选按钮添加到DOM中的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25413573/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com