传递变量来创建

使用 JavaScript 或 jQuery 的标签

发布于 2024-09-28 01:00:52 字数 1178 浏览 1 评论 0原文

不知道如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2024-10-05 01:00:52
// Inside the for loop, do this:
// This is the <h3> jQuery object you'll be inserting. I'm chaining the creation.
var h3 = $('<h3>').append($('<a>').attr('href', '#').text('name'))
$('#accordion').append(h3)
// This is the <div> object to be inserted into the accordion.
var div = $('<div>').append($('p').html('html inside first <p>'));
div = div.append($('p').html('html for history'))
$('#accordion').append(div)

这里的关键是你可以使用 $(parent).append($('')) 将内容添加到 DOM。 $('') 将创建该标签的一个新的 jQuery 对象,该对象只是浮动的。 .append(obj) 方法会将 obj 附加到调用它的父级的末尾。因此 $('#accordion').append($('

')) 将在 #accordion 末尾附加一个打开和关闭 h3 标记。

// Inside the for loop, do this:
// This is the <h3> jQuery object you'll be inserting. I'm chaining the creation.
var h3 = $('<h3>').append($('<a>').attr('href', '#').text('name'))
$('#accordion').append(h3)
// This is the <div> object to be inserted into the accordion.
var div = $('<div>').append($('p').html('html inside first <p>'));
div = div.append($('p').html('html for history'))
$('#accordion').append(div)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文