jquery html()替换整个fieldset

时间:2012-11-02 13:20:15

标签: jquery html

我正在尝试使用jquery更新选择框,而不是仅替换包含选择框的<div>html()正在取代整个<fieldset>。我已经尝试了一切,但却看不到我在哪里出错了。

我的jquery是:

$('div.companyselect', $(parent.document)).html(data.success);

我的HTML是:

<fieldset>
    <legend>Company Information</legend>
    <div class="column-left">
      <label>Manufacturer Name:</label>
      <div class="companyselect"><?php echo $select ?><div>&nbsp;

      <a href="../forms/modal_company.php" class="various fancybox.ajax" style="font-size:12px;">Add a Company</a>

    </div>
    <div class="clear"></div>  
 </fieldset>
 <fieldset>
    <legend>Vendor Information</legend>
    <div class="column-left">
      <label>First Name</label>
      <input name="name" class="text-input medium4-input required" type="text" id="name" value="">
    </div>
    <div class="column-right medium_margin">
      <label>Last Name:</label>
      <input name="last" class="text-input medium4-input required" type="text" id="last" value="">
    </div>
    <div class="clear"></div>
    <div>    
      <label>Address:</label>
      <input name="address" class="text-input medium2-input required" type="text" id="address" value=""> 
    </div>  
    <div class="clear"></div> 
    <div class="column-left" style="width:52%">
      <label>City:</label>
      <input name="city" class="text-input medium3-input required" type="text" id="city" value="" >
    </div>
    <div class="column-left" style="width:15%">
      <label>State:</label>
      <input name="state" class="text-input small-input required" type="text" id="state" value="">
    </div>
    <div class="column-left" style="width:30%">
      <label>Zipcode:</label>
      <input name="zipcode" class="text-input medium5-input required" type="text" id="zipcode" value="" >
    </div>
    <div class="clear"></div>
    <div class="column-left medium_margin">
      <label>Phone:</label>
      <input name="tel" class="text-input medium-input required" type="text" id="tel" value="">
    </div>
    <div class="column-right medium_margin">
      <label>(optional) Fax:</label>
      <input name="fax" class="text-input medium-input" type="text" id="fax" value="">
    </div>
    <div class="clear"></div> 
  </fieldset>

有人可以帮助我理解为什么整个第一个被替换而不仅仅是with class =“companyselect”??

2 个答案:

答案 0 :(得分:3)

很可能是由于HTML损坏:

<div class="companyselect"><?php echo $select ?><div>&nbsp;

应该是:

<div class="companyselect"><?php echo $select ?></div>&nbsp;

答案 1 :(得分:0)

您似乎错过了结尾div。

 <div class="companyselect"><?php echo $select ?><div>

在这里打开两个div标签,而不是关闭第一个标签。