2013-09-26 140 views
-1

我创建了一个小的文本编辑者,但是,问题是,当我点击后按钮,在MySQL后,我所有的文字涂黑(等)消失,我的意思是HTML代码!这里是我的代码:使<b></b><i></i><u>在文本框</u>和<br>

<script type="text/javascript"> 
function formatText(el,tag){ 
var selectedText=document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.selectionEnd);// IE:Moz 
var newText='<'+tag+'>'+selectedText+'</'+tag+'>'; 
if(document.selection){//IE 
document.selection.createRange().text=newText; 
} 
else{//Moz 
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value.length); 
} 
} 

</script> 
<?php 
//$maxlength = '9'; 
echo (
'<div class="enterNews"> 
<img style="float:left; width:1px; vertical-align:middle" src="icons/whiteHack.png"> 
<img style="float: left; padding:12px; width:20px; vertical-align:middle" src="icons/pencil.png"> 
<form enctype="multipart/form-data" name="changer" method="post" action="index.php"> 
<input class="enterNewsText" name="subject" id="subject" placeholder="'.$entersmallnews_lang.'" 
type="text" size="65" maxlength="149" onFocus="this.value='.$blank.'" /> 
<img style="float: right; padding:10px; width:20px; vertical-align:middle" src="icons/pic.png"> 
<div class="biggerNew">'); ?> 

<textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden" class="enterNewsTextBig" name="news" value="Enter big news" id="markItUp" >Enter Big news here...</textarea><br> 
<input type="button" value="Bold" onclick="formatText (news,'b');" /> 
<input type="button" value="Italic" onclick="formatText (news,'i');" /> 
<input type="button" value="Underline" onclick="formatText (news,'u');" /> 
<?php 
echo(' 
<input class="video" name="video" id="video" placeholder="Youtube video link" 
type="text" size="65" maxlength="149" />'); 
<div class="postcontainer"><input class="postFontan" type="Submit" name="submit" id="submit" value="'.$post_lang.'" /></div> 
</div></div></form> 
+1

哇......你真的需要缩进你的代码。这是完全不可读的。 – h2ooooooo

+0

另一件事:你说问题是当你插入文本到数据库,但你没有发布该插入的代码... –

+0

你是说全文正在从发布的值或从输入字段上消失这一页? –

回答

0

您的问题似乎是标记未定义,这意味着它会抛出一个错误。如果你在铬点击检查元素控制台日志,那么你可能会看到大量的错误

+0

也许textarea只是阻止html Hello world!按钮点击进入的代码?所以在mysql中它就是Hello world! – user2784722