用Javascript模式替换提示
Javascript modal to replace prompt?
更换的最佳方法是什么
var value = prompt("Enter a URL", "http://www.google.com/");
通过javascript模式(最好是纯javascript,如果不可能,则使用jquery)
谢谢!
您需要更改调用它的方式,因此它现在遵循事件驱动的编程风格,如下所示:
function prompt(question, callback) {
// here build a modal/form and after form submit:
callback(prompt_value);
}
然后像这样使用:
prompt('Enter a URL:', function(result){
// do something with the result:
alert(result);
});
为了获得更好的警报,您可以使用bootboxjs。
对于纯JS模态,您可以检查ModaliseJS,它与任何css类都兼容。
ModaliseJS的示例(根据您的设计更改类,只需保留一个.close
、.confirm
和.cancel
):
<!DOCTYPE html>
<html>
<head>
<title>Modal example</title>
<link href="../../dist/modalise.css" rel="stylesheet">
<script src="../../dist/modalise.js" type="text/javascript">
</script>
<script src="app.js" type="text/javascript">
</script>
</head>
<body>
<h1>Example modal 1</h1><button id="openModal">Show the modal</button>
<div class="mdl mdl-fadein" id="exampleModal">
<div class="mdl-content mdl-slidein">
<center>
<div class="mdl-header mdl-band-primary">
<span class="close">X</span>
<h2>Example modal</h2>
</div>
<div class="mdl-body">
<h3>Content modal</h3>
input data: <input type="text" class="inputdata"><br>
</div>
<div class="mdl-footer mdl-band-primary">
<button class="confirm" onclick="return false">Do
thing</button><button class="cancel" onclick=
"return false">Cancel the thing</button>
</div>
</center>
</div>
</div>
</body>
</html>
Javascript:
var myModal = {}
window.onload = function(){
var btnOpen = document.getElementById('queryData'); // The button to open the modal
// if btnsOpen is not given, you can simply use myModal.show()
// Modalise(id, options);
myModal = new Modalise('exampleModal', {
btnsOpen : [btnOpen]
})
.attach()
.on('onConfirm', function(){
console.log(this.querySelector(".inputdata").value);
});
}
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 我如何找到一个句子中的所有空格并替换忽略它们
- 如何用更合适的内容替换document.write
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 将“提示”对话框中的输入替换为星号时出现问题
- 是否可以替换或自定义getUserMedia提示
- 如何在 javascript 替换新图像/标题后正确显示 css 工具提示
- 将页面上的文本替换为 jQuery 并提示文件下载
- 使用 jquery 替换的 Highcharts 工具提示格式化程序
- Jquery:在一个字符串中查找所有实例模式,提示用户替换模式的所有实例,然后进行替换
- 为提示创建合适的替换项
- Emscripten:将提示替换为控制台(某种类型)
- 如何在“飞行”中替换工具提示数组值
- 用Javascript模式替换提示
- jquery即兴确认/提示替换
- "[对象对象]”;在警报提示中使用时替换变量字符串
- 替换Zurb Foundation的工具提示
- 用提示/回调UI替换正则表达式
- 替换& # 39;提示# 39;电子
- 将所有标题的默认工具提示替换为jQuery工具提示