简体   繁体   English

更改值后清除文本区域

[英]Clearing the textarea after changing the value

I am selecting a text on textarea and replacing it with newtext "shan"..The problem when I click on the submit button still the old text is submitted instead of new text.. 我正在选择textarea上的文本,并将其替换为newtext“ shan”。当我单击Submit按钮时,问题仍然是旧文本而不是新文本。

But this problem doesn't come when I press spacebar on keyboard and then press Submit button.. 但是当我按下键盘上的空格键然后按下Submit按钮时,不会出现此问题。

I can see the replaced text in "TextArea" but when I submit it the only the old text gets submitted.. 我可以在“ TextArea”中看到替换后的文本,但是当我提交它时,只会提交旧文本。

     var replacement text="shan";
    if (window.getSelection) {
       sel = window.getSelection();

    if (sel.rangeCount) {
        range = sel.getRangeAt(0);
        var e1=range.startContainer;
        var e2=e1.getElementsByTagName('textarea');
        e2[0].value=replacementText;
            e1.focus();
        }
     }    

Syntax Error? 语法错误?

var replacementText = "shan";
if (window.getSelection) {
    sel = window.getSelection();

    if (sel.rangeCount) {
        range = sel.getRangeAt(0);
        var e1 = range.startContainer;
        var e2 = e1.getElementsByTagName('textarea');
        e2[0].value=replacementText;
        e1.focus();
    }
}

Other things to look at or update your question with... 其他可以查看或更新的问题...

How are you submitting the form? 您如何提交表格?

Do you have the textarea named appropriately so that it will get sent back to the server properly? 您是否正确命名了textarea,以便将其正确发送回服务器? Are you getting the value out properly via javascript(if thats how you are posting back)? 您是否通过javascript正确地获取了价值(如果那是您回发的方式)?

Have you checked the post info with Fiddler or Firebug or Chrome to see what the request actually looks like? 您是否使用Fiddler或Firebug或Chrome浏览器查看了发帖信息,以查看请求的实际情况?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM