代码拷贝的是https://www.layui.com/doc/element/form.html,引入的css、js也是正确的。按照官网给进行更新渲染,出现的结果radio还是无效!求大佬解答一下,谢谢!
源代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../layui/css/layui.css" media="all">
<script src="../layui/js/layui.js" charset="utf-8"></script>
</head>
<body>
<!--head-->
<iframe width="100%" height="100%" src="./commons/head.html" frameborder="no" border="0" marginwidth="0"
marginheight="0" scrolling="no"></iframe>
<!-- body -->
<div class="layui-row">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md4 layui-col-md-offset4">
<form class="layui-form" lay-filter="index" action="">
<div class="layui-form-item">
<label class="layui-form-label">用户名</label>
<div class="layui-input-inline">
<input type="text" name="title" required lay-verify="required" placeholder="请输入用户名"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">密码框</label>
<div class="layui-input-inline">
<input type="password" name="password" required lay-verify="required" placeholder="请输入密码"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">单选框</label>
<div class="layui-input-block">
<input type="radio" name="landlord" value="房东" title="房东">
<input type="radio" name="renter" value="租客" title="租客">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
<button type="reset" class="layui-btn layui-btn-primary">注册</button>
</div>
</div>
</form>
</div>
</div>
<script>
layui.use(['form'], function(){
var form = layui.form;
//监听提交
form.on('submit(formDemo)', function(data){
layer.msg(JSON.stringify(data.field));
return false;
});
});
</script>
</body>
</html>
兄弟,
首先,你没有引用全layui的引用(去引用下载打包整个引用);
其次,你的radio得name需要保持一致,不能一个是landlord,一个是renter,如下图:
嗯,昨天晚上我把整个layui文件放到项目中才生效的。谢谢大佬!
对,我之前就是引用不完整,只拷贝了layui.css和layui.js的引用,导致我想要的功能没有,都是泪
我也是这样滴,,
问题已解决,谢谢各位大佬!
– 小锅牛 4年前