我需要在悬停时向li
添加一个类,但要从列表中的所有其他li
中删除相同的类(这是用于导航)。
我到目前为止的代码是:
jQuery(".navcontent").on('mouseenter', 'li', function() {
if (jQuery('.childmenu', this)) {
jQuery('.childmenu', this).addClass("child-active");
} else {
jQuery('.navcontent li .childmenu').removeClass("child-active");
}
});
我无法理解我需要做的事情......
非常感谢任何帮助。
答案 0 :(得分:2)
你有其他方法可以做到这一点:
jQuery(".navcontent li").on('mouseenter', function() { jQuery('.childmenu').removeClass("child-active"); jQuery('.childmenu', this).addClass("child-active"); });
siblings
:jQuery(".navcontent li").on('mouseenter', function() { jQuery('.childmenu', this).addClass("child-active") .siblings('.childmenu').removeClass("child-active"); });
答案 1 :(得分:1)
请检查以下代码
jQuery(".navcontent li").on('mouseenter', function(event) {
jQuery('.navcontent li').removeClass("child-active");
jQuery(this).addClass("child-active");
});

.child-active {
color: red;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<ul class="navcontent">
<li>Links</li>
<li>Links</li>
<li>Links</li>
<li>Links</li>
<li>Links</li>
</ul>
&#13;
答案 2 :(得分:0)
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con=new SqlConnection ("Data Source=SAGAR\\SQLEXPRESS;Initial Catalog=ClinicDb;Integrated Security=True");
con .Open();
SqlCommand sc=new SqlCommand ("insert into Patient_Details values('"+textBox1 +",'"+textBox2 +",'"+textBox3 +",'"+textBox4 +",'"+textBox5 +");",con );
int o = sc.ExecuteNonQuery();
try
{
if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0 || textBox3.Text.Length == 0 || textBox4.Text.Length == 0 || textBox5.Text.Length == 0)
MessageBox.Show("Fill all the fields");
else
MessageBox.Show("Values are Inserted successfully...!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
catch (Exception) { MessageBox.Show("something went wrong...Try Again"); }
MessageBox.Show(o + "saved");
con.Close();
}
答案 3 :(得分:0)
jQuery(".navcontent li").on('mouseover', function() {
jQuery(".navcontent li .childmenu").removeClass('child-active');
jQuery(this).addClass('child-active');
});
使用上面的代码
答案 4 :(得分:0)
jQuery(".navcontent li").on('mouseenter', function() {
jQuery(".navcontent li").removeClass("child-active");
jQuery(this).addClass("child-active");
});