简体   繁体   English

如何在可折叠小部件中编辑内容?

[英]How to edit Content inside Collapsible Widget?

I am working in Jquery Mobile and have hit my next brick wall, which I am hoping somebody will kindly point out where I am going wrong. 我在Jquery Mobile中工作,碰到了我的下一个砖墙,希望有人能指出我要去哪里。

I have a collapsible widget which within I wish to amend the content with different values. 我有一个可折叠的小部件,希望在其中用不同的值修改内容。

An example of my HTML 我的HTML示例

<div data-role="collapsible" data-mini="true" id="solar_collapsible">
<h3>Solar Power Information</h3>
<p id="solar_current"></p>
</div>

I am trying to amend id "solar_current" below: 我正在尝试在下面修改ID“ solar_current”:

document.getElementById("#solar_current").innerHTML = "Solar Current = 13";

Currently I receive this error in Google Chrome :- 目前,我在Google Chrome浏览器中收到此错误:-

Unable to set property 'innerHTML' of undefined or null reference 无法设置未定义或空引用的属性“ innerHTML”

I have stripped my code back but after searching all afternoon I can not find any reference or other questions relating directly to this problem. 我已经剥离了代码,但是在整个下午搜索之后,我找不到与该问题直接相关的任何参考或其他问题。

Has Solar_current not been created yet ? 尚未创建Solar_current吗? is this the reason for the error ? 这是错误的原因吗?

Thank you very much. 非常感谢你。

Seeing as you are using jQuery anyway, why not use it: 既然仍然使用jQuery,为什么不使用它:

$("#solar_current").html("Solar Current = 13");

You can run this in the pagecreate event of the page. 您可以在页面的pagecreate事件中运行它。

If you want to use plain javascript, just remove the "#" as Steve Hynding suggested.: 如果您想使用普通的javascript,只需按照Steve Hynding的建议删除“#”即可:

document.getElementById("solar_current").innerHTML = "Solar Current = 13";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM