我有一个脚本可以回显数据库值并让我突出显示它们。我有两个问题。第一个是值是按钮,而突出显示整个区域的颜色。我不会 CSS,所以我不知道如何解决这个问题。
第二个是主要问题。在突出显示一行并单击提交后,我想用突出显示的行的 id 更新一个表。这可能吗?
这是我的代码(是的,我知道这是一团糟,我只是在测试东西)。
感谢观看:)
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$('.category_list li').click(function(){
$('.highlight').removeClass('highlight');
$(this).addClass('highlight');
});
</script>
<style>
.highlight {background-color:yellow;}
ul.category_list {
margin: 35px 0;
padding: 0;
font: 12px Verdana;
list-style-type: none;
}
ul.category_list li a {
padding: 5px 10px;
border: 1px solid #aaa;
background-color: #eee;
color: #47a;
text-decoration: none;
}
</style>
</head>
<body>
<?php
include 'Includes/database_connection.php';
$sql = "select *
FROM sims" ;
$result = mysql_query($sql,$con);
while($row = mysql_fetch_assoc($result)){
?>
<form name="form" action="" method="post">
<ul class="category_list">
<li><a onclick="callGetApplicationDetails(0,0);" href="javascript:void(0);"><?php echo $row['phonenr'];?></a></li>
</ul>
<?php
}
?>
<input type="submit" name="submit" value="submit" />
</form>
</body>
最佳答案
这是否解决了您的 CSS 问题? http://jsfiddle.net/UPNYN/
只需修改您的 jQuery 即可将 a
添加到选择器:
$('.category_list li a').click(function(){
$('.highlight').removeClass('highlight');
$(this).addClass('highlight');
});
因为之前您的目标是 li
而不是其中的 a
。
然后快速准备好 !important
hack 到你的 CSS:
.highlight {background-color:yellow!important;}
关于jquery - 选择行更新数据库后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565654/