하고 cssPath를 얻기 위해, 나는 나에게 CSS 선택기를 돌려 다음 $.fn.cssPath
기능을 썼다 앞으로이 요소를 참조 할 수 있습니다. 지금까지 그 위대한 일.
$.fn.cssPath = function() {
var currentObject = $(this).get(0);
cssResult = "";
while (currentObject.parentNode) {
if(currentObject.id) {
cssResult = currentObject.nodeName + '#' + currentObject.id + " " + cssResult;
break;
} else if(currentObject.className) {
cssResult = currentObject.nodeName + '.' + currentObject.className + " " + cssResult;
} else {
cssResult = currentObject.nodeName + " " + cssResult;
}
currentObject = currentObject.parentNode;
}
return cssResult.toLowerCase();
}
$("*").mouseenter(function() {
$(".highlight").removeClass("highlight");
$(this).addClass("highlight");
});
$("*").bind('click',function(event){
var value = $(this).cssPath();
$('#web_page_filter',top.document).val(value);
return false;
});
테스터 코드가 짧고 정확히 같습니다. BTW,이 북마클릿은 간단한 자바 스크립트에서 원하는 것을 수행합니다. http://mrclay.org/index.php/2006/02/18/click2zap-bookmarklet/ (필요한 경우) –
14 개로 3 개의 답을 얻었습니까? 분?! 너무 대단해! – Jonathan