ajax和layeropen,layer.open()的content属性传参数方法

在使用layer弹窗的过程,发现layer.open的属性content可传入的值是灵活多变的,不仅可以传入普通的html内容,还可以指定DOM,更可以随着type的不同而不同。

方式一:使用字符串,直接在js里面拼接var html="

这是内容哦!

';

layer.open({

type: 1,

content: html,// 传入任意的文本或html , 这里content是一个普通的String

});

方式二:将需要的内容写到页面上,然后在使用的时候调用layer.open({

type: 1,

content: $('#id') //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响

});

方式三:Ajax获取内容$.post('url',{},function(str){

layer.open({

type: 1,

content: str //注意,如果str是object,那么需要字符拼接。

});

});

方式四:加载iframe,使用已经存在的页面,直接写url地址就可以了

layer.open({

type: 2,

content: 'http://sentsin.com' //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com','no']

});

方式五:如果是用layer.open执行tips层layer.open({

type: 4,

content: ['内容','#id'] //数组第二项即吸附元素选择器或者DOM

});