在jQuery中设置textarea的值 [英] Set value of textarea in jQuery

查看:83
本文介绍了在jQuery中设置textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有以下代码的jquery在textarea字段中设置一个值:

I am attempting to set a value in a textarea field using jquery with the following code:

$("textarea#ExampleMessage").attr("value", result.exampleMessage);

问题是,一旦执行此代码,就不会更改文本区域中的文本吗?

The issue is, once this code executes, it is not altering the text in the textarea?

但是在执行alert($("textarea#ExampleMessage").attr("value"))时会返回新设置的值吗?

However when performing an alert($("textarea#ExampleMessage").attr("value")) the newly set value is returned?

推荐答案

您尝试过val吗?

$("textarea#ExampleMessage").val(result.exampleMessage);

这篇关于在jQuery中设置textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆