我試圖在正在受到鍵控函數影響的div中插入下劃線或空白區域。目標是能夠移動文本中的空白處。 keyup函數工作正常,插入空格(div類下劃線)不是。用div在div中插入HTML
HTML:
<div class="bigwhitecard" id="bigwhitecard"></div>
<textarea id="text" placeholder="Type your card here" name="text"></textarea>
使用Javascript/jQuery的:
$(document).ready(function() {
$('#text').keyup(function(){
$('#bigwhitecard').html($(this).val());
});
var blankplace = 0;
$('#rightbtn').click(function() {
blankplace++;
});
$('#leftbtn').click(function() {
blankplace--;
});
var b = '<div class="underline"></div>';
$('#bigwhitecard').each(function() {
var blankplace = 0;
var txt = $(this).text();
if (txt.length>0) {
$(this).html(''+txt.substring(0,blankplace)+'<div class="underline"> </div>');
}
});
});
你能進一步擴大:「我們的目標是能夠移動其中的空白空間在文中「。你究竟是什麼意思? – roger
我打算讓用戶能夠選擇他們希望空白處在文本中的位置。 – Dustin