1

我正在尝试使用 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>

有人可以帮我理解为什么要替换整个 first 而不仅仅是 with class="companyselect" 吗?

4

2 回答 2

3

很可能是由于 HTML 损坏:

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

应该:

<div class="companyselect"><?php echo $select ?></div>&nbsp;
于 2012-11-02T13:21:45.500 回答
0

好像你错过了结尾的 div。

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

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

于 2012-11-02T13:23:42.397 回答