简体   繁体   English

如何创建链接以使用Javascript更改文本框值?

[英]How to create links to change textbox value using Javascript?

I am trying to use Javascript to create links to change the textbox value? 我正在尝试使用Javascript创建链接来更改文本框值?

What am I missing? 我想念什么?

This is what I have so far. 到目前为止,这就是我所拥有的。

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";
}

http://jsfiddle.net/y0qsvxes/ http://jsfiddle.net/y0qsvxes/

Change 更改

a.onClick = function() {
    replace();
};

to: 至:

a.onclick = function() {
    replace();
};

You can get away with the mixed case in HTML attributes, but Javascript properties are case-sensitive. 您可以忽略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 &amp;&amp; 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM