사용자가 아무 곳이나 클릭하여 요소를 클릭하면 클릭 한 번에 요소 유형을 변경하도록 jquery 코드가 있습니다.클릭 할 때 요소 유형 토글
문제는 CodePen의 어떤 이유로 든 클릭이 전혀 변경되지 않지만 원래 웹 사이트에서는 아무런 변화가 없다는 것입니다.
html로
<div>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary"><span class="btn"aria-hidden="true">Go</span></button>
</span>
</div>
자바 스크립트 : http://codepen.io/florinsimion/pen/AXxKbG
어떤 아이디어 : 여기
jQuery(document).ready(function() {
$.fn.changeElementType = function(newType) {
var attrs = {};
$.each(this[0].attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
this.replaceWith(function() {
return $("<" + newType + "/>", attrs).append($(this).contents());
});
}
$('.input-group-btn button').changeElementType('div');
$(function() {
$(".input-group div").on("click", function(e) {
$('.input-group-btn div').changeElementType('button');
e.stopPropagation()
});
$(document).on("click", function(e) {
if ($(e.target).is(".input-group input") === false) {
$('.input-group-btn button').changeElementType('div');
}
});
});
});
펜입니까?
콘솔에서 :'pen.js : 4 Uncaught TypeError : '정의되지 않은 속성'속성을 읽을 수 없습니다. – vaso123