【问题标题】:generated select does fire alert on change生成的选择确实会在更改时发出警报
【发布时间】:2012-10-12 07:34:20
【问题描述】:

我有一个生成的选择字段,其中包含 2 个这样的选项

<div class="PlentyFormContainer">
    <div class="PlentyFormContainer ArticleAttrTd_0 PlentyWebAttributeTitle">Rollen/Gleiter</div>
    <div class="PlentyFormContainer ArticleAttrTd_1 PlentyWebAttributeSelect">
        <select onchange="  this.blur();
                            switchImage(this.value ,'378_0', '378', aAttribute_Image_Values_378);
                            priceChangeOnMarkup(this.value, '2', '0', 'price_dynamic_0_378', aAttribute_Markup_Values_378, aCurrent_Markups_378, oldPrice_378);
                            "
                class="ArticleAttrSelect PlentyAttributeSelect_1" id="attr_row_0_378_2"
                name="ArticleAttribute[0][378][53]"><option value="" class="PlentyAttributeOption">-- bitte wählen --</option><option  value="1364" class="PlentyAttributeOption PlentyAttributeOption_1364">Rolle weich gebremst für harte Böden&nbsp;&nbsp;</option><option  value="1363" class="PlentyAttributeOption PlentyAttributeOption_1363">Rolle hart gebremst für Teppichboden&nbsp;&nbsp;</option>
                </select>
    </div>
</div>

整个 div-select 是由这些元素生成的:

<div class="plentyAttributeSelectWrapper">
   <div class="plentyAttributeSelectWrapperTitle"><span>Rollen/Gleiter</span>
   </div>
   <div class="plentyAttributeSelectWrapperContent plentyAttributeSelectHasDropdown"> 
      <div>
         <div class="plentyAttributeSelectedValue">
           <span class="plentyAttributeSelectedValueName">Rolle weich gebremst für harte Böden</span>
           <span class="plentyAttributeSelectedValueMarkup plentyAttributeSelectValueMarkup"></span><span class="plentyAttributeSelectedArrow">
           <span></span></span>
           <span class="clear"></span>
         </div>
        <div class="plentyAttributeSelectListWrapper">
         <ul>
          <li>
            <div class="plentyAttributeSelectValue">
               <a><span class="plentyAttributeSelectValueName">Rolle hart gebremst für Teppichboden</span>
              <span class="plentyAttributeSelectValueMarkup"></span></a>
           </div>
         </li>
         <li>
            <div class="plentyAttributeSelectValue">
               <a><span class="plentyAttributeSelectValueName">Rolle weich gebremst für harte Böden</span>
              <span class="plentyAttributeSelectValueMarkup"></span></a>
            </div>
         </li>
       </ul>
   </div>
 </div>
 </div>
</div>

如果我尝试在更改选项时强制发出警报,则没有反应。

【问题讨论】:

  • 对于初学者来说,看起来你在实际的选择元素而不是选项上有模糊。这可能是你不想要的。其次,我会将 blur 事件处理程序移动到单独的 js 文件中,而不是像您那样将其内联。

标签: jquery select alert option onchange


【解决方案1】:

您生成的代码很好。

它显示警报,如下所示:http://jsfiddle.net/ww5Rr/

<select onchange="this.blur(); alert('hi! \nAlert is working...');" >

也许您调用的函数(未在此处发布)内部有问题,导致您的警报无法显示。

尝试在 blur() 调用之后发出警报。

【讨论】:

    【解决方案2】:

    我尝试用 jquery 抓取选择:

    $('div.PlentyFormContainer select').change(function() {
        alert($(this).find('option:selected').text());
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-11
      • 2018-04-14
      • 1970-01-01
      • 2022-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多