第一个JS$(document).ready(function(){
$('.son_ul').hide(); //初始ul隐藏
$('.select_box span').hover(function(){ //鼠标移动函数
$(this).parent().find('ul.son_ul').slideDown(); //找到ul.son_ul显示
$(this).parent().find('li').hover(function(){$(this).addClass('more')},function(){$(this).removeClass('more')}); //li的hover效果
$(this).parent().hover(function(){},
function(){
$(this).parent().find("ul.son_ul").slideUp();
}
);
},function(){}
);
$('ul.son_ul li').click(function(){
$(this).parents('li').find('span').html($(this).html());
$(this).parents('li').find('ul').slideUp();
});
}
);第二个JS
function Scroll(obj, h, s) {
var h = h || 100;
var s = s || 1.2;
var obj = typeof(obj)=="string"?document.getElementById(obj):obj;
if(obj == undefined){return false;}
var status = obj.getAttribute("status")==null;
var oh = parseInt(obj.offsetHeight);
obj.style.height = oh;
obj.style.display = "block";
obj.style.overflow = "hidden";
if(obj.getAttribute("oldHeight") == null)
{
obj.setAttribute("oldHeight", oh);
}else
{
var oldH = Math.ceil(obj.getAttribute("oldHeight")); }
var reSet = function() {
if(status)
{
if(oh < h)
{
oh = Math.ceil(h-(h-oh)/s);
obj.style.height = oh+"px";
}
else
{
obj.setAttribute("status",false);
window.clearInterval(IntervalId);
}
}
else
{
obj.style.height = oldH+"px";
obj.removeAttribute("status");
window.clearInterval(IntervalId);
}
}
var IntervalId = window.setInterval(reSet,10); return status;
}
var $ = function(id){return document.getElementById(id)};
var number = document.getElementsByTagName('div');
window.onload= function()
{
for(var i = 0;i < number.length ;i++)
{
(function(i)
{
$('test'+i+'').onclick = function()
{
Scroll('test'+i+'',this.scrollHeight,1.2);
}
}
)(i);
}
} 第一个前端代码<div id="main_box" class="soso">
<ul>
<li class="select_box">
<span>搜全部</span>
<ul class="son_ul">
<li>找商户</li>
<li>找优惠</li>
<li>找商品</li>
</ul>
</li>
</ul>
</div>
单独拿出来都没问题,但放在一起就有问题了,第二个展开可以用,第一个失效。google提示冲突。
$('.son_ul').hide();和这个有冲突$('test'+i+'').onclick = function() 搞了半天没搞定,求解,搞定马上结贴给分~!十万分感谢
$('.son_ul').hide(); //初始ul隐藏
$('.select_box span').hover(function(){ //鼠标移动函数
$(this).parent().find('ul.son_ul').slideDown(); //找到ul.son_ul显示
$(this).parent().find('li').hover(function(){$(this).addClass('more')},function(){$(this).removeClass('more')}); //li的hover效果
$(this).parent().hover(function(){},
function(){
$(this).parent().find("ul.son_ul").slideUp();
}
);
},function(){}
);
$('ul.son_ul li').click(function(){
$(this).parents('li').find('span').html($(this).html());
$(this).parents('li').find('ul').slideUp();
});
}
);第二个JS
function Scroll(obj, h, s) {
var h = h || 100;
var s = s || 1.2;
var obj = typeof(obj)=="string"?document.getElementById(obj):obj;
if(obj == undefined){return false;}
var status = obj.getAttribute("status")==null;
var oh = parseInt(obj.offsetHeight);
obj.style.height = oh;
obj.style.display = "block";
obj.style.overflow = "hidden";
if(obj.getAttribute("oldHeight") == null)
{
obj.setAttribute("oldHeight", oh);
}else
{
var oldH = Math.ceil(obj.getAttribute("oldHeight")); }
var reSet = function() {
if(status)
{
if(oh < h)
{
oh = Math.ceil(h-(h-oh)/s);
obj.style.height = oh+"px";
}
else
{
obj.setAttribute("status",false);
window.clearInterval(IntervalId);
}
}
else
{
obj.style.height = oldH+"px";
obj.removeAttribute("status");
window.clearInterval(IntervalId);
}
}
var IntervalId = window.setInterval(reSet,10); return status;
}
var $ = function(id){return document.getElementById(id)};
var number = document.getElementsByTagName('div');
window.onload= function()
{
for(var i = 0;i < number.length ;i++)
{
(function(i)
{
$('test'+i+'').onclick = function()
{
Scroll('test'+i+'',this.scrollHeight,1.2);
}
}
)(i);
}
} 第一个前端代码<div id="main_box" class="soso">
<ul>
<li class="select_box">
<span>搜全部</span>
<ul class="son_ul">
<li>找商户</li>
<li>找优惠</li>
<li>找商品</li>
</ul>
</li>
</ul>
</div>
单独拿出来都没问题,但放在一起就有问题了,第二个展开可以用,第一个失效。google提示冲突。
$('.son_ul').hide();和这个有冲突$('test'+i+'').onclick = function() 搞了半天没搞定,求解,搞定马上结贴给分~!十万分感谢
解决方案 »
- 大家真的觉得IntelliJ IDEA很智能吗,怎么我用它写js却感觉很多提示不出来
- 请问这2个数组怎么遍历,对比?麻烦大虾给我写一下程序流程.
- 网站访问问题(自己测试的网站)
- 怎样限定DIV拖动的范围,求高手帮忙,在线等~~~万分感谢
- 如何得到动态创建的控件的值
- 关键词:linux,javascript,firefox,视频播放,wmv
- 如何使用js将一些Array数据,按照一定的格式显示在网页中呢?
- 如何用JS或VBS实现清空文本框内容功能?
- 如何在javascript中调用aspx页面的后台函数?
- 怎样动态产生下拉列表值?点击省份列表,产生相应城市名称
- 这两个表达式,怎么会给我把数字过滤了,如果要他不过滤数字,该怎么写。
- Js问题
var $ = function(id){return document.getElementById(id)};
$变量改成别的,如$$