Javascript在加载表单后添加href

时间:2015-04-16 15:25:49

标签: javascript href

我有3个下拉菜单。只有在从国家/地区下拉列表中选择澳大利亚时,我才需要显示城市下拉列表的帮助超链接。用户在选择澳大利亚之前可以阅读一些指导原则。为此,我想追加城市'带有href的标签。我怎样才能做到这一点?我尝试了以下但失败了:

function ddCountryChange() 
 {
     var ddCountry = document.getElementById("ddCountry");
     var tbCity = document.getElementById("tbCity ");
     if (ddCountry.value == "AUS"){               
            tbCity.innerHTML = '<div class="GXIRowTitle"><a href="/City-Search.ashx" target="_blank" style="color:blue">[<u>Help</u>]</a>&nbsp;<span style="font-weight:normal;">City : &nbsp;&nbsp;</span></div><div class="GXIRowControl"><div id="ctl02_ctl00_GXDivLeft_TbCity_TbBoxReadOnly" style="display: none;">&nbsp;</div><span id="ctl02_ctl00_GXDivLeft_TbCity_TbBoxNonReadOnly" style="display: inline;"><input name="ctl02$ctl00$GXDivLeft$TbCity$TbBox" type="text" maxlength="64" id="ctl02_ctl00_GXDivLeft_TbCity_TbBox" autocomplete="off"><ul id="ctl02_ctl00_AcCity_completionListElem" class="GXAutoComplete_CompletionListElement" style="position: absolute;"></ul></span><input type="image" name="ctl02$ctl00$GXDivLeft$TbCity$Btn" id="ctl02_ctl00_GXDivLeft_TbCity_Btn" align="ABSMIDDLE" src="/ucommand/CRM/images/icn/DropDown.gif" alt="Show List" onclick="javascript:onAutoCompleteViewList("ctl02_ctl00_AcCity");return false;" style="border-width:0px;"></div>';
        }
 }

在通过Firebug进行调试时,我发现城市标签附有“帮助”,但是一旦流程完成,“帮助”就会显示出来。消失。

1 个答案:

答案 0 :(得分:0)

假设ddCountry是选择元素

 // Detect when value is changed
ddCountry.addEventListener("change", function(e){

  // Is its value now "AUS"?
  if(this.value == "AUS"){
      // Do stuff such as appending whatever label
  }else{
      // Hide stuff again?
  }

});