本文介绍了获取点击元素jQuery的HTML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有以下HTML < label class =editableid =user_info_username>海世界。 ..< /标签> 现在点击功能我需要点击元素的内容。 我试过了 $ b $ $ p $ $ $ $ $ $。editable)。live(click,function() { alert($(this).html())//返回海世界... }); 但我需要HTML内容 所以< label class =editableid =user_info_username>海洋世界...< / label> < div> 中,然后询问HTML的内容 - 例如: var html = $('< div />')。append($(this).clone ())的HTML(); 在 http://jsfiddle.net/f88kj/ 我之前也写过一个插件,它在 https://stackoverflow.com/a/6509421/6782 $ .fn.outerhtml = function(){ return $('< div />')。append(this.clone()) .html(); }; })(jQuery); I have the following HTML <label class="editable" id="user_info_username">Hai world...</label>now on click function i need the content of the clicked element .i tried $(".editable").live("click",function(){alert($(this).html()) //returns Hai world...});But i need the HTML contentso <label class="editable" id="user_info_username">Hai world...</label> 解决方案 Clone the clicked element, wrap it in a <div>, and then ask for the HTML of that - something like:var html = $('<div/>').append($(this).clone()).html();Working demo at http://jsfiddle.net/f88kj/I also previously wrote a plugin that does this at https://stackoverflow.com/a/6509421/6782(function($) { $.fn.outerhtml = function() { return $('<div/>').append(this.clone()).html(); };})(jQuery); 这篇关于获取点击元素jQuery的HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 18:35