所以我做一個文本編輯器,但我需要做的是需要在文本編輯器來調整字段後,我輸入的東西
1)當我鍵入說「Col1中」後來我一按空格鍵它應爲「第1欄」
我是新來的HTML和JS自動完成,看見的onkeyup一些例子和監視事件,但它似乎沒有滿足或我可能會得到一些錯誤
任何幫助將深受讚賞
順便說一句,使用NicEdit作爲基地
我的HTML
<html>
<head>
\t <title>Custom Text Editor</title>
</head>
<body>
<div id="menu"></div>
<div id="intro">
By calling the nicEditors.allTextareas() function the below example replaces all 3 textareas on the page with nicEditors. NicEditors will match the size of the editor window with the size of the textarea it replaced.
</div>
<br />
<div id="sample">
<script type="text/javascript" src="../nicEdit.js"></script>
<script type="text/javascript">
\t bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>
<h4>Rich Text</h4>
<textarea name="area1" cols="40" style="width: 100%" onkeyup="myFunction()"></textarea>
<br />
<h4>Second Textarea</h4>
<textarea name="area2" style="width: 100%;">
\t Some Initial Content was in this textarea
</textarea>
<br />
<h4>Third Textarea</h4>
<textarea name="area3" style="width: 300px; height: 100px;">
\t HTML <b>content</b> <i>default</i> in textarea
</textarea>
</div>
</body>
</html>
<script>
function myFunction() { var x = document.getElementById("a").value; document.getElementById("abc").innerHTML = x; }
</script>
非常感謝您的答覆,邏輯似乎是正確的,但我想我沒有得到文本字段ID正確,所以它沒有得到應用,而檢查文本字段時,它顯示我一個div,但它沒有顯示在我的HTML代碼:/ – Venky
使用此簡單的輸入文本字段的作品,但就像我說我的HTML代碼中沒有可見的文本字段ID,但顯示我一個,當我嘗試通過鉻瀏覽器檢查該字段,我應該添加這個js腳本? – Venky
@Venky Answer更新。立即嘗試並讓我知道。一開始我不明白你正在使用nicEdit插件。 – gaetanoM