<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,问别人是最后的手段
----------------------------------------------------------------------
是啊,基本上有提供个思路或者方向,比自己盲目的乱找快多了,还是谢谢你们!

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

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.

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.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software