k80*_*0sg 2 javascript vb.net asp.net
我试图将控件的id传递给一个javascript函数,它将它的值(控件是一个文本框)添加到列表框但显然我没有把它弄好,有人可以请你纠正我.
谢谢.
<input type="button" ID="btnAddtoLstBox" value="" title="Add this to the list" onclick="javascript:addToList(document.getElementById(btnAddtoLstBox));"
class="ui-icon ui-icon-refresh ui-corner-all" style="width: 20px; height: 20px; background-position: -64px 80px" />
// scripts to add list items
function addToList(varTxtBox) {
// get the list box
var lb = document.getElementById("uilstMemTypeTier");
// get the text to add
var toAdd = varTxtBox.value;
if (toAdd == "") return false;
// look for the delimiter string. if found, alert and do nothing
if (toAdd.indexOf(delim) != -1) {
alert("The value to add to the list cannot contain the text \"" + delim + "\" as it is used as the delimiter string.");
return false;
}
// check if the value is already in the list box
for (i = 0; i < lb.length; i++) {
if (toAdd == lb.options[i].value) {
alert("The text you tried to add is already in the list box.");
return false;
}
}
// add it to the hidden field
document.getElementById("<%=uihdnlistBasedFieldsListItems.ClientID%>").value += toAdd + delim;
// create an option and add it to the end of the listbox
lb.options[lb.length] = new Option(toAdd, toAdd);
// clear the textfield and focus it
varTxtBox.value = "";
varTxtBox.focus();
}
Run Code Online (Sandbox Code Playgroud)
更改onclick="javascript:addToList(document.getElementById(btnAddtoLstBox));"到onclick="addToList(document.getElementById('btnAddtoLstBox'));" 或onclick="addToList(this);"
| 归档时间: |
|
| 查看次数: |
22955 次 |
| 最近记录: |