2013-01-19 46 views
-1

我已经构建并排序了输出当前变量的对象,如下所示。当帐单信息地址和送货地址相同时的警报

我想警惕......两个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;} 
+9

[你有什么尝试?](http://www.whathaveyoutried.com/)请参阅[常见问题]。 –

+1

打我吧,^ –

+1

我建议:使用PHP来判断内容是否相同。如果是这样,请将CSS类应用于DIVS以指示相同的内容。 – showdev

回答

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> 
+0

感谢所有的帮助,我完成了,你可以看到我上面的编辑。虽然我没有使用你的代码,但我会注意到它以备将来参考。谢谢。欢迎您致电 –

+0

,很高兴为您服务。 –

2

你是正确的,包括PHP和jQuery。您可以在JavaScript中的客户端或PHP中的服务器上执行此操作。尝试一下,当有问题时再回来。

在PHP中,您可以使用比较结果在div上设置CSS类。然后在样式表中设置基于该类的背景颜色。

在JavaScript中它会更复杂,但不需要去服务器。

+0

是不是我downvoted,但我会建议这应该是一个评论。 – Hailwood

+0

everybodys downvoting everything ..什么给... ehhh –

+0

它回答没有勺子喂养的OP问题。有些人太快而不满意。我会留下你曾尝试过的评论,但它已经在那里了,我刚刚投了票,还有“你打败了我”。 –

相关问题