-2
<html>
    <head>
        <script type="text/javascript" src="file:///C:/jquery-1.7.1.min.js"></script>
        <script>
        $(document).ready(function(){
            var showGoals = $('<button>Show Globals</button>').click(function () { alert('hi')});
            var resp1 = $('<button>Show locals</button>').click(function () { alert('hi2')});

            $("#newId").append(showGoals, resp1);
            $("#newId").show();
        });
        </script>
    </head>
    <body>
        <div id="newId" style="display:none"></div>
    </body>
</html>

我希望将按钮分别封装在 div class="span4" 和 div class="span12" 中。有人可以帮忙吗。我是 jQuery 的新手。

4

1 回答 1

1

你可以这样做,例如:

var showGoals = $('<button>Show Globals</button>').click(function () { alert('hi')});

var showGoalsWrapper = $('<div class="span4"></div>');
showGoalsWrapper.append(showGoals);    

var resp1 = $('<button>Show locals</button>').click(function () { alert('hi2')});

var resp1Wrapper = $('<div class="span12"></div>');
resp1Wrapper.append(resp1);

$("#newId").append(showGoalsWrapper, resp1Wrapper);
$("#newId").show();
于 2013-06-26T19:59:37.647 回答