传递变量来创建和使用 JavaScript 或 jQuery 的标签
使用 JavaScript 或 jQuery 的标签
不知道如何使用 javascript 或 jquery 让我的 div 填充手风琴样式标题和内容。
<代码> <头> <脚本类型=“text/javascript”src=“js/jquery-1.4.2.min.js”> <脚本类型=“text/javascript”src=“js/jquery-ui-1.8.2.custom.min.js”> <脚本类型=“text/javascript”> $(文档).ready(函数() { $("#accordion"). 手风琴( 自动高度:假); }); /** 多变的 *variableID:String - 变量的唯一字符串标识符 * name:String - 纯文本名称 * description:String - 变量的描述及其含义 * value:Integer - 变量当前基于数字的值 * Locked:Boolean - 变量是否被锁定以防止进一步修改 */ 函数 loadVariables(变量) { 如果(变量类型!=“对象”){ 警报(变量);返回;} for (var i = 0; i < 变量.length - 1; i++) { /* make name=name
; 使变量ID、描述、值=“变量 ID:” + 变量 ID
“描述:”+描述
“初始值:”+值
“历史”
*/ } }; 函数 updateVariable(变量) { // 当变量值发生变化时更新历史框中的变量 // 更改背景颜色并更改锁定图标状态 }; <正文>
updateVariable 函数的容器。
Not sure how to use javascript or jquery to make my divs populate with accordian style headings and content.
<html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#accordion").accordion( autoheight: false); }); /** Variable * variableID:String - unique string identifier for the variable * name:String - plain text name * description:String - description of the variable and its meaning * value:Integer - current number-based value of the variable * locked:Boolean - whether the variable is locked against further modification */ function loadVariables(variables) { if (typeof variables != "object") { alert(variables); return;} for (var i = 0; i < variables.length - 1; i++) { /* make name= <h3><a href="#">name</a></h3> make variableID, description, value= <div> <p>"Variable ID : " + variableID</br> "Description : " +description</br> "Initial Value : " +value</br> </p> <p>"History"</br> A container for updateVariable function. </p>*/ } }; function updateVariable(variable) { // make update Variable in the History box as variable values change // change background color and change locked icon status }; </script> </head> <body> <div id="accordion"> <!--- Divs Created Dynamically here ----> </div> </body> </html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的关键是你可以使用
$(parent).append($('')) 将内容添加到 DOM。 $('')
将创建该标签的一个新的 jQuery 对象,该对象只是浮动的。 .append(obj) 方法会将 obj 附加到调用它的父级的末尾。因此$('#accordion').append($('
'))
将在 #accordion 末尾附加一个打开和关闭 h3 标记。The key here is that you can add things to the DOM with
$(parent).append($('<tag-name>')). $('<tag-name>')
will create a new jQuery object of that tag that is just floating. The .append(obj) method will attach the obj at the end of the parent that is calling it. So$('#accordion').append($('<h3>'))
will append an open and close h3 tag at the end of #accordion.