调用layui.use中function的正确姿势

适用于

  • obj.click()
  • 行内onclick

代码如下

<html>

	<head>
		<link rel="stylesheet" href="layui/css/layui.css"  media="all">
	head>
	<body>
	
		<a class="layui-btn" id="test" href="javascript:;">测试a><br/><br/>
		<a class="layui-btn" onclick="hello('this is a test')" href="javascript:;">helloa>
		<script src="layui/layui.js">script>
		<script type="text/javascript">
		
			layui.use(["jquery","layer","form"],function(){
				var $ = layui.$,layer = layui.layer,form = layui.form;
				$("#test").click(function(){
					hello("张三");
				});
				
				window.hello = function(obj) {
					layer.msg("hello world,"+obj);
				}
			});
			
		script>		
		
	body>
html>
复制代码

测试结果

  • 点击测试按钮

  • 点击hello按钮

你可能感兴趣的:(javascript)