我已經搜索瞭如何註冊一個Javascript文件後面的代碼.cs,但仍然不明白它,我試過的東西不會觸發Javascript。如何註冊加載的Javascript
我怎麼能火內
protected void Page_Load(object sender, EventArgs e)
{
}
現有的JavaScript函數,我已經試過
Page.ClientScript.RegisterStartupScript(Type.GetType, "script", "return myFunction()");
但它說,它具有參數無效?以及我懸停紅色下劃線時的一堆例外情況。
謝謝你的幫助。
功能
function myFunction() {
var combo = $find("<%= myClients.ClientID %>");
//prevent second combo from closing
cancelDropDownClosing = true;
//holds the text of all checked items
var text = "";
//holds the values of all checked items
var values = "";
//get the collection of all items
var items = combo.get_items();
//enumerate all items
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
if (chk1.checked) {
text += item.get_text() + ",";
values += item.get_value() + ",";
}
}
//remove the last comma from the string
text = removeLastComma(text);
values = removeLastComma(values);
if (text.length > 0) {
//set the text of the combobox
combo.set_text(text);
}
else {
//all checkboxes are unchecked
//so reset the controls
combo.set_text("");
}
}
即使javascript函數已經在前端代碼的標籤? – user710502
@安迪,不符合MSDN。看看他們的例子:http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerstartupscript(v=vs.71).aspx。它們包括腳本標籤。 –
@ User710502,是的。 –