2014-02-13 2 views
1

이유는이 HTML로하여 myFunction()가 onkeyup 호출 할 수 있습니다콘텐츠 편집 가능한 div 내에서 HTML 태그 내에서 함수를 호출하려면 어떻게해야합니까?

<div contenteditable="true" onkeyup="myFunction()" >A function is triggered when the user is pressing a key in the input field.</div> 

하지만이 사용하여 수행 할 수 없습니다 두 번째에서

<div contenteditable="true">A function is <span onkeyup="myFunction()" >triggered</span> when the user is pressing a key in the input field.</div> 

, 나는 단지 그것을 호출하려고 해요 특정 단어가 triggered인데 차이점을 모르겠습니다. 감사.

HTML (당신이 스팬이 아닌 부모 단락에서의 contentEditable 설정해야 노트, 그것은 둘 수 없습니다) :

체크 아웃 FIDDLE

+0

@GSiry'b'는 실제로 HTML 요소이며 ... w3schools 링크를 게시하지 않습니다. – kapa

+0

@GSiry ^^ 이것과 같은 사이트는 실제로 당신이 말하는 것과 모순되며'b' 엘리먼트로 키보드 이벤트를 사용할 수 있다고 말합니다 ... http://www.w3schools.com/tags/tag_b.asp – Archer

+0

http://jsfiddle.net/wTy3C/1/보세요 b없이 span과 div를 사용했지만 여전히 작동하지 않았습니다 – Squirrl

답변

0

이 시도

<p>A function is <span class="bold" contenteditable="true" onkeyup="myFunction()" >triggered</span> when the user is pressing a key in the input field.</p> 

<p contenteditable="true" onkeyup="myFunction()" >A function is triggered when the user is pressing a key in the input field.</p> 

<div id='foo'>Not Yet</div> 

CSS :

.bold { font-weight: bold; } 

피들 : http://jsfiddle.net/wTy3C/2/