문제

I'm trying to enable the tabulation module in my project. Working module I took from http://css-tricks.com/snippets/javascript/support-tabs-in-textareas/ , but when I add this .js to my project i get the following error:

Uncaught TypeError: Cannot set property 'onkeydown' of undefined. 

Its work when i run it on http://jsfiddle.net/zQgTx/ but doesnt work, when I run it in my project. Using jquery-1.9.1. My html code:

 <form method="POST" action="." class="navbar-form">
    <textarea id="answer" name="answer" style="width: 700px; height: 250px;"></textarea>
    <br><input class="btn btn-primary" type="submit" value="Check">
 </form>

Help solve the problem. Thanks!

도움이 되었습니까?

해결책

Wrap all your code in onload function like this:

window.onload = function(){

   // Your code;

}

Issue happens because when this line runs :

var textarea = document.getElementsByTagName('textarea')[0]; 

your textarea is not actually loaded. onload will solve it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top