从动态文本区域获取价值

时间:2018-05-03 18:32:31

标签: javascript jquery sharepoint-online

我有一个文本区域字段,我想获得该文本区域的值,所以我尝试通过javascript获取:

var body = "Descripción";
var _body = $("div[title='" + body + "']");

文字区域

<textarea rows="10" cols="20" id="Descripci_x00f3_n_9b68a148-3221-43c6-abf3-bb32afd3e51b_$TextField" title="Descripción Campo obligatorio" class="ms-long"></textarea>

但我只是得到对象而不是价值。

出于某种原因,当我在文本区域中写入时,此输入会更改为我想要的值:

<input id="ClientFormPostBackValue_742e5004-4272-4f68-b3b9-a3c9e3d9ba9b_Descripci_x00f3_n" name="ClientFormPostBackValue_742e5004-4272-4f68-b3b9-a3c9e3d9ba9b_Descripci_x00f3_n" type="hidden" value="this is the value I want">

如何从此输入中检索值?此致

2 个答案:

答案 0 :(得分:1)

&#13;
&#13;
var body = "Descripción";
//use `^=` to denote that the attribute should start with a string
var _body = $("textarea[title^='" + body + "']");

console.log(_body.val());
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<textarea rows="10" cols="20" id="Descripci_x00f3_n_9b68a148-3221-43c6-abf3-bb32afd3e51b_$TextField" title="Descripción Campo obligatorio" class="ms-long">
  Stuff
</textarea>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您想在点击按钮后获取数据吗?如果是的话。

&#13;
&#13;
function run() {
    var textbox = document.getElementById("Descripci_x00f3_n_9b68a148-3221-43c6-abf3-bb32afd3e51b_$TextField").value;
    document.write(textbox);
}
</script>
&#13;
<textarea rows="10" cols="20" id="Descripci_x00f3_n_9b68a148-3221-43c6-abf3-bb32afd3e51b_$TextField" title="Descripción Campo obligatorio" class="ms-long"></textarea>
<br/>
<button type="button" onclick="run()">get</button>
&#13;
&#13;
&#13;