jQuery 节点的查询_html/css_WEB-ITnose
<a id = 1>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><a id = 2>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><a id = 3>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul>
------------------------jQuery代码如上面
回复讨论(解决方案)
如上所示 点击某一个
$("li").click(function(event){ alert($(this).parent().prev().attr("id"));});
$("li").click(function(event){ alert($(this).parent().prev().attr("id"));});
$("li").click(function(event){ alert($(this).parent().prev().attr("id"));});
<html><head> <title>test</title> <script src="http://jquery.cuishifeng.cn/js/jquery-2.1.4.min.js?v=20160120"></script></head><body><a id = '1'>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><a id = '2'>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><a id = '3'>XX</a><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><script>$("li").click(function(event){ alert($(this).parent().prev().attr("id"));});</script></body></html>
引入jquery,并且你的dom结构写正确
$("li").click(function(event){ alert($(this).parents("a").attr("id"));});
这样呢?
引入jar包,js区域写上
$(function(){
$("li").click(function(event){
alert($(this).parent().prev().attr("id"));
});
})
<p class="yy"> 引入jar包,js区域写上$(function(){ $("li").click(function(event){ alert($(this).parent().prev().attr("id")); });}) </p>也不可以。。无法获取
我贴部分源码。
<h3 id="a-nbsp-id-nbsp-nbsp-XX-a"><a id = '1'>XX</a></h3><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><h3 id="a-nbsp-id-nbsp-nbsp-XX-a"><a id = '2'>XX</a></h3><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul><h3 id="a-nbsp-id-nbsp-nbsp-XX-a"><a id = '3'>XX</a></h3><ul><li>xx</li><li>xx</li><li>xx</li><li>xx</li></ul>$.ajax({xxxxxxsuccess:function(){ $("ul li:last-child").bind("click", Addhut);}}); function Addhut() { // parId = $(this).parent().filter("a").attr("id"); parId = $(this).parent("a").prev().attr("id"); alert(parId);}
具体结构就是这样,页面载入时执行ajax函数,成功后执行回调函数。最后一个li标签绑定Addhut函数 点击后 获得上面的的id
跪求大神答疑解惑!
你检查你的事件,我们给你的基本都可以
你检查你的事件,我们给你的基本都可以
为什么我的 一直提示 undefined
你检查你的事件,我们给你的基本都可以
---------------------------绑定函数的一样可以吗------------------------------------
你的bind的格式不对,这是点击每项的最后一个弹出提示
你的bind的格式不对,这是点击每项的最后一个弹出提示
嗯啊 搞定了 3Q
不客气,不懂的可以多百度,查api,问别人是最后的手段
不客气,不懂的可以多百度,查api,问别人是最后的手段
----------------------------------------------------------------------
是啊,基本上有提供个思路或者方向,比自己盲目的乱找快多了,还是谢谢你们!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...
