[英]Trying to use JavaScript to send generated text to specific P tags
In an iPhone app i have started to develop, I have created some sample text using PhoneGap's FileWriter API document, and then used FileReader to read the file back to the user. 在我开始开发的iPhone应用程序中,我已经使用PhoneGap的FileWriter API文档创建了一些示例文本,然后使用FileReader将该文件读回用户。 Currently the file is displayed in a separate HTML page and it need to go to specific <p>
tags with the id 'mytext'. 当前,该文件显示在单独的HTML页面中,它需要转到ID为'mytext'的特定<p>
标记。
function readmyfile(){
var myPara = documentGetElementById("mytext");
myPara.write(text);
}
<p>
tags and 'text' is the sample text created by a different function. “ mytext”是<p>
标记中的ID,“ text”是由其他函数创建的示例文本。 the first line of the function definelty works, it's the second that's the problem. 函数definelty的第一行有效,而第二行就是问题所在。 I need the app to send the sample text to the <p>
tags and i'm not sure how to do that. 我需要该应用程序将示例文本发送到<p>
标记,但我不确定如何执行此操作。
If you need any more info or code just comment it and i'll put it in an edit. 如果您需要更多信息或代码,请对其进行注释,然后我将其进行编辑。
HTMLElements don't have a write
method. HTMLElement没有write
方法。 You want to write to the innerHTML
or innerText
property. 您要写入innerHTML
或innerText
属性。
var myPara = document.getElementById("mytext");
myPara.innerText = text;
For getting the object, you will need this: 为了获得对象,您将需要以下内容:
document.getElementById("mytext");
You will need to use innerText
or textContent
to actually write text in to the p
element. 您将需要使用innerText
或textContent
将文本实际写入p
元素。
Try: 尝试:
myPara.innerText = text;
or 要么
myPara.textContent = text;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.