我试图在正在受到键控函数影响的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