将php附加到div并维护当前的css

时间:2012-08-10 00:16:49

标签: php jquery

好的..这是lo_add.php文件:

<div class="rowElem">
    <label>Item <? echo $i ?>:</label>
    <div class="formRight searchDrop">
        <select name="lo_item[]" class="chzn-select" data-placeholder="Choose an Item">
            <option value=""></option>
            <? $item_query = mysql_query("select id,code,title,price from items where domain_id='$domain_id' order by code");
            while ($items = mysql_fetch_array($item_query)) { ?>
                <option value="<? echo $items["id"] ?>"><? echo $items["code"]." - ".$items["title"]." - RM".$items["price"] ?></option>
            <? } ?>
        </select>
    </div>
    <label>Delivery Address :</label>
    <div class="formRight searchDrop">
        <select name="lo_site[]" class="chzn-select" data-placeholder="Choose a Delivery Address">
            <option value=""></option>
                <? $site_query = mysql_query("select id,name from sites where domain_id='$domain_id' order by name");
                while ($sites = mysql_fetch_array($site_query)) { ?>
                    <option value="<? echo $sites["id"] ?>"><? echo $sites["name"] ?></option>
                <? } ?>
        </select>
    </div>
    <div class="fix"></div>
    <label>Quantity:<span class="req">*</span></label>
    <div class="formRight onlyNums">
        <input type="text" name="lo_quantity[]" id="lo_quantity[]"/>
    </div>
    <div class="fix"></div>
</div>

这是调用css的html文件以及开头的内容:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>Mecacom Technologies&reg; Maintenance System &copy; 2012</title>

<link href="/css/main.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Cuprum' rel='stylesheet' type='text/css' />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
  $('#addElement').click(function() {
    var data = '';
    $.get('/ajax/lo_add.php', data, function(response){
      $('#hello').append(response);
    });
  });
});
</script>

</head>
<body>
    <div class="content" id="container">
        <div class="title"><h5>Record New Local Order</h5></div>

        <form action="<? echo $PHP_SELF ?>?add=1" id="valid" class="mainForm" method="post" enctype="multipart/form-data">
            <fieldset>
                <div class="widget">
                    <div class="head"><h5 class="iLocked2">New Local Order Credentials</h5></div>

                    <div class="rowElem noborder">
                        <label>Order ID:<span class="req">*</span></label>
                        <div class="formRight">
                            <input type="text" class="validate[required]" name="order_id" id="order_id"/>
                        </div>
                        <div class="fix"></div>
                   </div>

                    <div class="rowElem noborder">
                        <label>Order Date:<span class="req">*</span></label>
                        <div class="formRight">
                            <input type="text" name="order_date" class="datepicker validate[required]" />
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div id="hello"></div>

                    <div class="fix"></div>
                    <a href="#" id="addElement">Click To Append More Item</a>
                    <input type="submit" value="Next" class="greyishBtn submitForm" />
                    <div class="fix"><input type="hidden" name="addnow" value="1" /></div>
                </div>
            </fieldset>

        </form>
    </div>
</body>
</html>

叹息 ..相当少......你认为在jquery附加后css没有正确呈现?

1 个答案:

答案 0 :(得分:1)

我可以从您的实时测试页面看到您正在使用Chosen来处理下拉列表,并使用jQuery validation plugin来验证数量字段。

首先要确保在新创建的下拉菜单上调用chosen()。必须为新元素调用它,因为Chosen不仅依赖于CSS,还会更改下拉列表的整个HTML结构。所以在追加后添加这一行,

$(".chzn-select").chosen()

其次是确保通过调用validate()来验证新创建的数量文本字段,或者重新调用您调用的任何javascript以初始化验证插件。