[英]Javascript Adding a href after form is loaded
I have 3 dropdowns. 我有3个下拉菜单。 Only when Australia is selected from the country dropdown, I have to show a help hyperlink for the city dropdown. 仅当从国家下拉列表中选择澳大利亚时,我才需要显示城市下拉列表的帮助超链接。 The user can read some guidelines when he selects Australia before he can select a city. 用户在选择澳大利亚之前可以阅读一些准则,然后再选择城市。 For this I want to append the 'City' label with an a href. 为此,我想在“城市”标签上附加一个href。 How can I achieve this? 我该如何实现? I tried the following but failed: 我尝试了以下操作,但失败了:
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> <span style="font-weight:normal;">City : </span></div><div class="GXIRowControl"><div id="ctl02_ctl00_GXDivLeft_TbCity_TbBoxReadOnly" style="display: none;"> </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>';
}
}
While debugging through Firebug, I see that the city label is appended with a 'Help', but once the process finishes, the 'Help' disappears. 通过Firebug进行调试时,我看到城市标签后面附加了“帮助”,但是一旦过程完成,“帮助”就会消失。
Assuming ddCountry
is the select element 假设ddCountry
是select元素
// 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?
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.