使用jQuery将javascript id放入div中
把hello这个词放在我所有的班级“盒子”里。它们都有一个指定的id 我想知道如何把每个部门的id而不是“hello”放在部门里。也许这真的很容易,但我想不出来。我也是jQuery的新手。有什么想法吗?我试过:使用jQuery将javascript id放入div中,javascript,jquery,Javascript,Jquery,把hello这个词放在我所有的班级“盒子”里。它们都有一个指定的id 我想知道如何把每个部门的id而不是“hello”放在部门里。也许这真的很容易,但我想不出来。我也是jQuery的新手。有什么想法吗?我试过: $('div.box').html("hello") 试试这个: $("div.box").html("id: " + $(this).attr("id")); 完整示例: $("div.box").each(function() { $(this).html("Id: " +
$('div.box').html("hello")
试试这个:
$("div.box").html("id: " + $(this).attr("id"));
完整示例:
$("div.box").each(function() {
$(this).html("Id: " + this.id);
});
布局
方框一
方框二
方框三
方框四
load(“jquery”,“1.3.1”);
setOnLoadCallback(函数(){
$(函数(){
$(“div.box”)。每个(函数(){
$(this.html(“ID:+this.ID”);
});
});
});
您需要循环浏览每个项目
<html>
<head>
<title>Layout</title>
</head>
<body>
<div id="id1" class="box">Box One</div>
<div id="id2" class="box">Box Two</div>
<div id="id3">Box Three</div>
<div id="id4" class="box">Box Four</div>
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.3.1");
google.setOnLoadCallback(function() {
$(function() {
$("div.box").each(function() {
$(this).html("ID: " + this.id);
});
});
});
</script>
</body>
</html>
那真是奇怪。。。接受然后不接受。稍纵即逝。:)
$("div.box").each(function()
{
$(this).html("id: " + this.id);
});