我已经构建并订购了输出当前变量的对象,如下所示。
我希望警报......两个div突出显示为绿色。我假设我需要加入一些jquery ..这就是我所拥有的:
<div class='address_info left'>
<h3>Billing Info</h3>
<ul>
<li><label>Account No: </label><?php echo $order->patient_id;?></li>
<li><label>Name: </label><?php echo trim($order->billing_address['name']); ?></li>
<li><label>Address 1: </label><?php echo trim($order->billing_address['addr1']);?></li>
<li><label>Address 2: </label><?php echo trim($order->billing_address['addr2']);?></li>
<li><label>City, State, Zip:</label><?php echo trim($order->billing_address['city'] . ' ' . $order->billing_address['state'] . ' ' . $order->billing_address['zip']);?></li>
<li><label>Email: </label><a href='mailto:<?php echo $order->customer_email;?>'>Send Customer Email</a></li>
<li><label>Phone: </label><?php echo $order->customer_phone;?></li>
</ul>
</div>
<div class='address_info right'>
<h3>Shipping Info</h3>
<ul>
<li><label>Name: </label><?php echo $order->shipping_address['name']; ?></li>
<li><label>Address 1: </label><?php echo $order->shipping_address['addr1'];?></li>
<li><label>Address 2: </label><?php echo $order->shipping_address['addr2'];?></li>
<li><label>City, State, Zip:</label><?php echo $order->shipping_address['city'] . ' ' . $order->shipping_address['state'] . ' ' . $order->shipping_address['zip']?></li>
<li><label></label></li>
<li><label></label></li>
<li><label></label></li>
</ul>
</div>
我正在使用一些css悬停颜色。
div.address_info.left:hover {
background: red;
color: #fff; }
div.address_info.right:hover {
background: #5C991F;
color: #fff; }
div.order_info:hover {
background: #3366FF;
color: #fff; }
所以这是我的更新:
if (count(array_diff($this->billing_address, $this->shipping_address)) > 0)
return false;
else
return true;
我想我真正的问题是如何在我的数据上运行jquery事件。很抱歉在开始时再次如此模糊..我猜我们没有在右脚下车。不过会喜欢jQuery的一些帮助。提前谢谢。
感谢所有的帮助..我想出来了!
if($order->check_addresses())
$class='same';
else
$class='different';
<div class='address_info left <?php echo $class; ?>'>
<div class='address_info right <?php echo $class; ?>'>
而不是css
div.same {background-color: green;}
div.different {background-color: red;}
答案 0 :(得分:2)
包含PHP和jquery是正确的。您可以在JavaScript中的客户端上或PHP中的服务器上执行此操作。试试看,遇到问题后再回来。
在PHP中,您可以使用比较结果在div上设置CSS类。然后在样式表中设置基于该类的背景颜色。
在JavaScript中它会更复杂,但不需要去服务器。
答案 1 :(得分:2)
使用隐藏输入可以非常轻松地完成此操作。以下是使用您的代码的示例。
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function()
{
var BillAddy = $("#billing").val();
var ShipAddy = $("#shipping").val();
if(BillAddy == ShipAddy)
{
$(".address_info ").css("backgroundColor","#00FF00");
return true;
}
return false;
});
</script>
</head>
<body>
<div class='address_info left'>
<h3>Billing Info</h3>
<ul>
<input type="hidden" id="billing" value="<?php echo $order->billing_address; ?>" />
<li><label>Account No: </label><?php echo $order->patient_id;?></li>
<li><label>Name: </label><?php echo trim($order->billing_address['name']); ?></li>
<li><label>Address 1: </label><?php echo trim($order->billing_address['addr1']);?></li>
<li><label>Address 2: </label><?php echo trim($order->billing_address['addr2']);?></li>
<li><label>City, State, Zip:</label><?php echo trim($order->billing_address['city'] . ' ' . $order->billing_address['state'] . ' ' . $order->billing_address['zip']);?></li>
<li><label>Email: </label><a href='mailto:<?php echo $order->customer_email;?>'>Send Customer Email</a></li>
<li><label>Phone: </label><?php echo $order->customer_phone;?></li>
</ul>
</div>
<div class='address_info right'>
<h3>Shipping Info</h3>
<ul>
<input type="hidden" id="shipping" value="<?php echo $order->shipping_address; ?>" />
<li><label>Name: </label><?php echo $order->shipping_address['name']; ?></li>
<li><label>Address 1: </label><?php echo $order->shipping_address['addr1'];?></li>
<li><label>Address 2: </label><?php echo $order->shipping_address['addr2'];?></li>
<li><label>City, State, Zip:</label><?php echo $order->shipping_address['city'] . ' ' . $order->shipping_address['state'] . ' ' . $order->shipping_address['zip']?></li>
<li><label></label></li>
<li><label></label></li>
<li><label></label></li>
</ul>
</body>
</html>