我从数据库加载多个DIV
我点击的Javascript
<script type="text/javascript">
$(document).ready( function() {
var role = 0;
$(".role").click(function(){
if(role == 0)
{
role = 1;
$(".role").text("Decision Approver");
}
else if(role == 1)
{
role = 2;
$(".role").text("Decision Maker");
}
else if(role == 2)
{
role = 3;
$(".role").text("Influencer");
}
else if(role == 3)
{
role = 4;
$(".role").text("Gate Keeper");
}
else if(role == 4)
{
role = 5;
$(".role").text("User");
}
else if(role == 5)
{
role = 6;
$(".role").text("Stake-holder");
}
else if(role == 6)
{
role = 0;
$(".role").text("");
}
});
});
</script>
我的DIV“角色”CSS
{
position: absolute;
width: 50px;
min-height:20px;
height:auto;
border:1px solid #000;
word-wrap: break-word;
float:left;
font-size:12px;
z-index: 30;
margin-top:50px;
margin-left:3px;
}
这是HTML
$qry = "SELECT * from contact";
$result = mysql_query($qry);
while ($row = mysql_fetch_array($result))
{
<div class="role" align="center" ></div>
}
已生成多个DIV,当我点击一个DIV角色时,所有DIV角色都会更改其文本。如何单独更改每个DIV并通过contactID将其更新到数据库?
答案 0 :(得分:0)
假设您想使用jQuery来执行此客户端(并且基于此假设我不知道SQL在标记或问题中做了什么)我建议使用数组来包含新文本:
var textValues = ['Decision maker', 'Decision approver', 'influencer']; // and so forth
$('.role').text(function(i){
return textValues[i];
});
上面将迭代每个.role
元素,i
表示当前元素的索引(在集合中的其他元素中),并将文本设置为包含在i
数组中的textValues
位置。
参考文献:
答案 1 :(得分:0)
我认为在更新角色时,所有条件都是一个接一个地满足,所以你需要包含return false;这与休息相似;