코드가 아래에 있습니다.이 추론의 뒷바침에 초점을 맞추었지만 포커스/흐림 이벤트는 이벤트가 두 번째로 활성화 될 때만 활성화됩니다. 나는 현재 다른 어떤 것에 대해서도 걱정하지 않는다. 그러나 왜 이것이 처음으로 무엇에 달렸는지에 대한 추리.jQuery 스크립트는 두 번째 이벤트에서만 실행됩니다.
JS :
var App = function() {
this.page = window.location.pathname.split("/public/portal/")[1].split("/")[0];
}
$.extend(App.prototype, {
// This will set the variables in the box and display/hide
setVariables: function (ele, vars) {
this.variables = vars || variables;
var list = $("#page_variables .text_variables");
// Create the variable box
$('li', list).remove(); // first remove all variables currently in the box
console.log(ele);
ele.bind('focus', function() {
list.fadeIn();
})
.bind('blur', function() {
list.fadeOut();
});
}
});
(function ($, undefined) {
$(".tvar_text").focus(function() {
port.setVariables($(this), null);
});
})(jQuery);
HTML : 당신은 포커스 이벤트 핸들러에서 포커스 이벤트를 바인딩하기 때문에입니다
<div id="page_variables">
<div class="text_variables" style="display:none">
<ul>
<strong style="text-decoration: underline;">VARIABLES</strong>
<li>{provider}</li>
<li>{date}</li>
<li>{callerid}</li>
<li>{time}</li>
<li>{location}</li>
<li>{recipient}</li>
<li>{misc1}</li>
<li>{misc2}</li>
<li>{misc3}</li>
<li>{misc4}</li>
</ul>
</div>
</div>
<textarea class="tvar_text" name="Vtmpl" cols="50" rows="10" style="min-height: 200px; overflow: hidden; resize: none; height: 50px;"></textarea>
:
가 선택 일치하는 각 요소에 함수를 호출하려면each
방법을 사용합니다. 그래서 포커스 핸들러가 아닌 메소드를 호출하십시오. BTW, 요소가 집중 될 때마다 새로운 포커스/흐림 처리기를 바인딩합니다. 그리고 제발, 들여 쓰기 코드 –들여 쓰기가 있습니다. 복사/붙여 넣기가 올바르게 탭되지 않습니다. 방법을 어떻게 호출해야하는지에 대한 예를 들어 줄 수 있습니까? 새로운 바인딩에 대한 당신의 말을 봅니다. – jamadri