0

我在 aspx 页面上有两个 dropdownsddl1、ddl2 和一个按钮 btn。当我单击按钮时,需要从两个下拉列表中获取显示所选项目值的警报框。我可以知道如何通过网络方法做到这一点...

按钮:

<input  id="Test" type="button" value="clickme" onclick='<%# String.Format("showingddlvalues(\"{0}\")",Eval("ddl1ID")) %>' />

网络方法:

[网络方法]

    public static string showingddlvalues(string ddl1ID)
    {
        return String.Format("showing selected ddl1ID{0} value here ", ddl1ID);
    }

jQuery:

function showingddlvalues(ddl1ID) {
    $.ajax({
        type: "POST",
        url: "Default.aspx/showingddlvalues",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: "{ddl1ID:'" + ddl1ID + "'}",
        success: AjaxSucceeded,
        error: AjaxFailed
    });
}

function AjaxSucceeded(result) {
    alert(result.d);
}

function AjaxFailed(result) {
    alert('error:' + result.status + ' ' + result.statusText);
}​

请纠正我哪里出错了。

4

2 回答 2

1

像这样修改你的 jQuery & web 方法并再次检查结果:

jQuery:

function showingddlvalues(ddl1ID) {

    var value = $('#' + ddl1ID).val();

    $.ajax({
        type: "POST",
        url: "Default.aspx/showingddlvalues",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: "{value:'" + value + "'}",
        success: AjaxSucceeded,
        error: AjaxFailed
    });
}​

网络方法:

[WebMethod]
public static string showingddlvalues(string value)
{
    return String.Format("{0}", value);
}
于 2012-12-07T12:09:39.100 回答
0

尝试,

var js = $('#idOfDrop option:selected').text();

或者

var js = $("[name=nameOfSelect] :selected")

警报(js);

您将从下拉列表中获取所选值

于 2012-12-07T10:51:43.697 回答