下拉列表引用数据库数据 JS编写随机生成二维码
2018-09-13 14:08
525 查看
当你需要一个二维码,二维码里有你想表示的内容或者想进入的网页的时候应该怎么办呢?
今天看看一个随机二维码的生成:
所用工具:
Microsoft Visual Studio 2010
SQL Server Management Studio
首先:我们得引入俩个库:
然后,我们得引入一个控件:
该控件是一个下拉列表控件 onchange="makeCode()"方法是调用下面的JS方法
接下来就是生成二维码的JS方法了
里面的DropDownList2是调用了数据库里面的数据传入的是DropDownList2.SelectedValue.
如果不懂这个下拉的方法,可以直接使用输入框的方法。
也是需要引入jquery.min.js和qrcode.min.js两个库
今天看看一个随机二维码的生成:
所用工具:
Microsoft Visual Studio 2010
SQL Server Management Studio
首先:我们得引入俩个库:
<script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script> <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
然后,我们得引入一个控件:
<asp:DropDownList ID="DropDownList2" runat="server" Height="16px" Width="322px" AutoPostBack="True" onchange="makeCode()" > </asp:DropDownList>
该控件是一个下拉列表控件 onchange="makeCode()"方法是调用下面的JS方法
接下来就是生成二维码的JS方法了
<script type="text/javascript"> var qrcode = new QRCode(document.getElementById("qrcode"), { width: 100, height: 100 }); function makeCode() { var elText = document.getElementById("DropDownList2"); if (!elText.value) { elText.focus(); return; } qrcode.makeCode(elText.value); } makeCode(); $("#text"). on("blur", function () { makeCode(); }). on("keydown", function (e) { if (e.keyCode == 13) { makeCode(); } }); </script>
里面的DropDownList2是调用了数据库里面的数据传入的是DropDownList2.SelectedValue.
如果不懂这个下拉的方法,可以直接使用输入框的方法。
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
<title>Javascript 二维码生成器:QRCode</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script> <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
</head>
<body>
<input id="text" type="text" value="http://www.runoob.com" style="width:80%" /><br />
<div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
<script type="text/javascript">
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 100,
height : 100
});
function makeCode () {
var elText = document.getElementById("text");
if (!elText.value) {
alert("Input a text");
elText.focus();
return;
}
qrcode.makeCode(elText.value);
}
makeCode();
$("#text").
on("blur", function () {
makeCode();
}).
on("keydown", function (e) {
if (e.keyCode == 13) {
makeCode();
}
});
</script>
</body>
</html>
也是需要引入jquery.min.js和qrcode.min.js两个库
相关文章推荐
- Excel调用已有数据利用已经录入的项快速的生成下拉列表
- 数据库中数据添加到下拉列表的实现方法
- Mock.js -- 生成随机数据,拦截 Ajax 请求,让前端攻城师独立于后端进行开发
- JS随机生成不重复数据的代码分享
- 关于asp.net自动生成树形下拉列表(数据库版)
- Struts中将数据库中的内容动态生成下拉列表内容
- 从数据库获取数据填充下拉列表,然后选中特定项提示不存在的问题。
- js动态生成级联下拉列表
- 在js中如何遍历List集合,并且动态渲染下拉列表数据
- jsp中,使用js生成动态的数据库相关的二级联动下拉框
- JSP自定义标签实例---从数据库读取数据放在下拉列表中
- c# winform comboBox动态下拉列表,comboBox动态绑定数据库里的数据
- 如何使用Visual Studio 2010在数据库中生成随机测试数据
- Mock.js生成随机数据,拦截 Ajax 请求,让前端独立于后端进行开发
- js控制select数据绑定下拉列表
- 关于js动态向下拉列表中添加数据
- 用Ajax实现多级联动下拉列表For JSP(无限级别,JSON传输数据,含全国地区数据库
- 关于“Asp.net 中后台CS读取数据库数据生成数组传递给前台页面JS使用”
- DWR使用体会2:获取数据库表数据,使用addRows生成列表
- js动态生成数据列表