简体   繁体   English

如何在文本框中获取新输入的值

[英]How to get new entered value in a textbox

I have a textbox in which I render some value the user can change. 我有一个文本框,在其中呈现了用户可以更改的一些值。 If user does, then I have to show a popup and tell him that The new text you entered in textbox is this... 如果用户这样做,那么我必须显示一个弹出窗口,并告诉他您在文本框中输入的新文本是这个...

If he clicks OK then I will submit that to DB. 如果他单击“ 确定”,那么我会将其提交给数据库。 How to do that in JavaScript? 如何在JavaScript中做到这一点?

Suppose default value of textbox is 假设文本框的默认值为

What,are,you,doing

and user enters this 然后用户输入

What,are,you,doing,james

in this case user enters only james . 在这种情况下,用户仅输入james

jQuery jQuery的

oldVal = $('#textBoxID').val();

$(document).ready(function() {
    $('#submit').on('click', function() {
       alert('You Entered: ' + $('#textBoxID').val().replace(oldVal, ''));

       // Submit form

       window.oldVal = $('#textBoxID').val();          
    });
});

HTML 的HTML

<textarea id="textBoxID">What,are,you,doing</textarea>
<button id="submit">OK</button>

example jsfiddle 例子jsfiddle

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

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