<div id="search_ebook_vcode" style="display: none;">
<div class="layui-form" style="margin: 10px;">
<div class="layui-form-item">
<label class="layui-form-label">验证码</label>
<div class="layui-input-block">
<input type="text" name="search_vcode" id="search_vcode" placeholder="请输入验证码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<img id="captchaPic" src="{$cfg[weburl]}index.php?comment-vcode-name-searchvcode" onclick="this.src='{$cfg[weburl]}index.php?comment-vcode-name-searchvcode-r-'+Math.random();" alt="验证码">
</div>
</div>
</div>
</div>
<script>
layui.use(['form','layer'], function () {
var layer = layui.layer, $ = layui.$, form = layui.form;
$(".search_ebook").click(function () {
var keyword = $('input[name="keyword"]').val();
if(keyword == ''){
layer.msg("请输入搜索关键字", {icon: 5});
}else{
layer.open({
id: 'search_open',
type: 1,
title: '请输入验证码',
shade: 0.6,
shadeClose: true,
maxmin: true,
anim: 0,
content: $("#search_ebook_vcode").html(),
btn: ['确定', '取消'],
btn1: function(index, layero){
var search_vcode = $("#search_vcode").val();
alert(search_vcode);
}
});
}
});
});
</script>
点击【确定】就是不能获取input的值,总是为空字符串。
后来在网上查找资料,原来这是个比较普遍的bug,原来是layer.open的content参数,应该写成
content: $("#search_ebook_vcode"),
不要后面的html(),去掉后调试正常获取了input的值。
特此记录~~~
layer.open({
id: 'search_open',
type: 1,
title: '请输入验证码',
shade: 0.6,
shadeClose: true,
maxmin: true,
anim: 0,
content: $("#search_ebook_vcode"),
btn: ['确定', '取消'],
btn1: function(index, layero){
var search_vcode = $("#search_vcode").val();
alert(search_vcode);
}
});
发表评论