我想更改我的文本框的 css 并在 php 循环中禁用提交按钮(如果它满足特定条件)。
我已经成功地设法通过 php 循环数据,但只有第一个文本框发生了变化
我会放一些 php 代码,因为 php 部分已经成功完成了
脚本
<style type="text/css">
.first
{
color:#0C0
}
.second
{
color:#F00
}
</style>
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery-ui.js" > </script>
<script> var $j = jQuery.noConflict();
function changeClass(str)
{
if ($j('#status').val()== "No")
{
$j('#status').addClass('first');
}
else
{
$j('#status').removeClass('first');
$j('#status').addClass('second');
$j('#submit').prop('disabled', true);
}
return true;
}
</script>
HTML
<table width="800" border="0" align="center" bordercolor="#000000"
onmousemove="changeClass(this);">
<?php do { ?>
<tr bgcolor="#FFFFCC">
<th align="center" bgcolor="#3366FF" class="style68" >Status</th>
<th align="center" bgcolor="#3366FF" class="style68" >Submit</th>
<td align="center" bgcolor="#CCCCCC">
<form > <input type="text" id="status" name="status"
value="<?php echo$data['status']; ?>" >
</td>
<td align="center" bgcolor="#CCCCCC">
<button id="submit" name="submit" type="submit" > Submit</button>
</form>
</td>
</td>
</tr>
<?php } while ($data = mysql_fetch_assoc($re)); ?>
</table>
最佳答案
$(document).ready(function(){
$('table').hover(function(){
$( ".changeClass" ).each(function() {
if($(this).val()=='No')
{
$(this).addClass( "second" );
$(this).parent().parent().find('.submitClass').prop('disabled', true);
}
else
{
$(this).addClass( "first" );
}
});
return true;
})
});
<input type="text" class="changeClass" name="status" value="<?php echo$data['status']; ?>" >
关于javascript - 如何在 php 循环中使用 jquery 更改 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14870608/