如何将文本保存到 DOM

发布于 2024-10-03 12:06:21 字数 285 浏览 1 评论 0原文

我如何使用 jQuery 来实现这一点。我在页面上有两个文本输入,因此当用户输入文本并离开输入字段时,是否将该文本插入到 DOM 中以便我可以访问它?

编辑:

为了澄清我有这个:

Expected Delivery Date: <input id="exp" type="text"></input>

我想做的是打印页面的内容,但它不打印这个输入值?

这是我需要用户提供的唯一输入,因此我想避免只为一个输入提交表单!

How can i achieve this using jQuery. I have two text inputs on the page, so when the users has entered text and left the input field, for that text to be inserted into the DOM so i can access it?

EDIT:

To clarify i have this:

Expected Delivery Date: <input id="exp" type="text"></input>

What i'm trying to do is print the contents of the page, but its not printing this input value?

This is the only input i need from the user so i wanted to avoid having to submit the form just for one input!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花细雨 2024-10-10 12:06:21

您的输入已经在 DOM 中,您可以使用 .val()< 获取它们的值/a> 像这样:

var myValue = $("#inputID").val();

您可能需要使用不同的选择器,但想法保持不变,它是 $(selector).val(),或者可能是 this,例如,如果您想要用户离开时的值:

$("input").blur(function() {
  alert($(this).val());
});

您可以在这里测试

Your inputs are already in the DOM, you can get their value using .val() like this:

var myValue = $("#inputID").val();

You may need to use a different selector but the idea stays the same, it's $(selector).val(), or possible this, for example if you want the value when the user leaves:

$("input").blur(function() {
  alert($(this).val());
});

You can test it here.

胡大本事 2024-10-10 12:06:21

像这样的东西吗?

$('.my-input-fields').blur(function() {

   var div = $('<div/>');
   div.html( $(this).val() );

   $('#DOMplaceOfEntry').append(div);

});

Something like this?

$('.my-input-fields').blur(function() {

   var div = $('<div/>');
   div.html( $(this).val() );

   $('#DOMplaceOfEntry').append(div);

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文