【发布时间】:2016-08-15 13:20:00
【问题描述】:
我想为我的 Android 应用制作一个 WhatsApp 分享按钮。一切都设置好了,唯一的问题是只有点击按钮才能获取textarea值:
<button onclick="GetValue ();">Get the value of the textarea!</button>
我想GetValue(); 没有onclick。
这是我的 WhatsApp 代码:
<a href="whatsapp://send" data-text="GetValue ();" data-href="" class="wa_btn wa_btn_s" style="display:none">Share</a>
我想要 data-text 属性中的 textarea 值,我像上面一样使用它,但它不起作用。
这是我的文本区域:
<textarea id="input_output" style="width:95%;" rows="10" wrap="soft">Enter Text Here..
</textarea>
有什么方法可以在不点击按钮的情况下获取值?
这是我的功能:
GetValue () {
var area = document.getElementById ("input_output");
alert (area.value);
}
【问题讨论】:
-
尝试在链接上绑定
mousedown或touchstart事件以将data-text属性设置为document.getElementById("input_output").value。 -
你的函数甚至没有返回这个值。它只是提醒它。
-
如何返回值?抱歉,我对 JS 不太了解 :( @Xufox
-
return area.value;。说真的,如果您要编写 JS 代码,只需 Google 基本 JS 文档/介绍。
标签: javascript android jquery html css