2016-08-09 4 views
0

私は、単純な検索フィールドのdivを持っていますが、ここで問題があります:カーソルが復帰しないようにする方法は?

enter image description here

私は私のコード(ではない別のライブラリ)を使用して、このファッションのキャリッジリターン、を防ぐためにしたいと思います。

ここに私のhtmlです:

<div id="search" contenteditable="true" oninput="searchChanged()"></div> 

Javascriptを:

function searchChanged() { 
    queries.search = document.getElementById("search").innerText; 
    if (!queries.search.match(/\S/)) { delete queries.search; } 
    updateURL(); 
    updateSearch(); 
} 

とCSS:

#search { 
    width:200px; 
    height:25px; 
    background-color:#fcfcfc; 
    outline: 1px solid #eee; 
    focus:none; 
    position:absolute; 
    text-align: left; 
    vertical-align: middle; 
    right:5px; 
    margin-top:22px; 
    padding-left:5px; 
} 
+0

あなたはこのような何かをしたいですか?..私は、この作品の場合は投稿されたすべてのmultiliineもの – repzero

+0

見ますbrタグを隠すことで、複数のhackinessを無効にすることができます –

+0

チェック答えを無効にすることを好むと思い、感謝@repzeroデモここhttps://jsfiddle.net/repzeroworld/cc5cygwt/ – repzero

答えて

0

ソリューション

function searchChanged() { 
 
    queries.search = document.getElementById("search").innerText; 
 
    if (!queries.search.match(/\S/)) { delete queries.search; } 
 
    updateURL(); 
 
    updateSearch(); 
 
}
#search { 
 
    width:200px; 
 
    height:60px; 
 
    background-color:#fcfcfc; 
 
    outline: 1px solid #eee; 
 
    focus:none; 
 
    position:absolute; 
 
    text-align: left; 
 
    vertical-align: middle; 
 
    overflow:auto; 
 
    margin-top:22px; 
 
    padding-left:5px; 
 
} 
 
#search br{ 
 
display:none; 
 
}
<div id="search" contenteditable="true" oninput="searchChanged()"></div>
は、

関連する問題