我正在尝试使用Javascript创建链接来更改文本框值?
我错过了什么?
这是我到目前为止所做的。
createLink("A");
createLink("B");
createLink("C");
createLink("D");
function createLink(queueName) {
var a = document.createElement("a"); // Create a <a> node
a.innerHTML = queueName;
a.title = queueName;
a.style.marginLeft = "5px";
a.href = "javascript:void(0);";
a.onClick = function () {
replace();
};
document.getElementById('newOwn_top').appendChild(a);
}
function replace() {
document.getElementById("newOwn_mlktp").selectedIndex = 1;
document.getElementById("newOwn").value = "a";
}
答案 0 :(得分:0)
更改
a.onClick = function() {
replace();
};
为:
a.onclick = function() {
replace();
};
您可以使用HTML属性中的混合大小写,但Javascript属性区分大小写。
createLink("A");
createLink("B");
createLink("C");
createLink("D");
function createLink(queueName) {
var a = document.createElement("a"); // Create a <a> node
a.innerHTML = queueName;
a.title = queueName;
a.style.marginLeft = "5px";
a.href = "javascript:void(0);";
a.onclick = function () {
replace();
};
document.getElementById('newOwn_top').appendChild(a);
}
function replace() {
document.getElementById("newOwn_mlktp").selectedIndex = 1;
document.getElementById("newOwn").value = "a";
}
<tr>
<td class="data2Col" colspan="3">
<div class="requiredInput">
<div class="requiredBlock"></div>
<div id="newOwn_top" name="newOwn_top" style="white-space: nowrap">
<select id="newOwn_mlktp" name="newOwn_mlktp" onchange="LookupAutoCompleteInputElement.handleLookupTypeChange('newOwn',false);if
(getElementById('newOwn_lktp').value.search('queue') < 0 &&
false) {
getElementByIdCS('sendMail').checked = true;
} else {
getElementByIdCS('sendMail').checked = false;
}" title="Search scope">
<option value="005" selected="selected">User</option>
<option value="case_queue">Queue</option>
<option value="PartnerUserLookup">Partner User</option>
<option value="NonLpuCustomerSuccessUserLookup">Customer Portal User</option>
</select>
<input type="hidden" name="newOwn_lkid" id="newOwn_lkid" value="000000000000000">
<input type="hidden" name="newOwn_lkold" id="newOwn_lkold" value="null">
<input type="hidden" name="newOwn_lktp" id="newOwn_lktp" value="StandardUserLookup">
<input type="hidden" name="newOwn_lspf" id="newOwn_lspf" value="0">
<input type="hidden" name="newOwn_lspfsub" id="newOwn_lspfsub" value="0">
<input type="hidden" name="newOwn_mod" id="newOwn_mod" value="0"><span class="lookupInput"><input id="newOwn" maxlength="255" name="newOwn" onchange="getElementByIdCS('newOwn_lkid').value='';getElementByIdCS('newOwn_mod').value='1';" size="20" title="Owner name" type="text"><a href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3DeditPage%26lknm%3DnewOwn%26lktp%3D%27%20%2B%20getElementByIdCS%28%27newOwn_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27newOwn%27%29.value.substring%280%2C%2080%29%29%29" id="newOwn_lkwgt" onclick="setLastMousePosition(event)" secid="newOwn_mlbtn" title="Owner name"></a></span>
</div>
</div>
</td>
</tr>