0

我是一个有两个按钮的 jquery 对话框。

<div id="generatePinsDialog" title="Generate New PINs">

<input type="button" title="button1" id="button1" />
<br />
<input type="button" title="button2" id="button2" />

在我的 js 文件中,我想设置字符串 vlaue 并将其传递给 wcf 方法。

function OpenGeneratePINsDialog() {
$("#generatePinsDialog").dialog('open');
$.get('/MyServices/myService.svc/GeneratePINs/' + #button1.val()+'/' + #button2.value 

}

WCF 方法:

[OperationContract]
    [WebGet(UriTemplate = "/.../GeneratePINs/{button1}/{button2}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
    public void GeneratePINs(string button1, string button2)
    {  

这意味着如果单击 button1,则传递 button1=1 和 button2 =0 如果单击 button2,则传递 button2=1 和 button1 =0

感谢帮助。另外请帮我纠正button1的值的写法。

           #button1.Val() or $(#button1.Val())
4

2 回答 2

4
    function OpenGeneratePINsDialog(e) {
        var b1=0, b2=0; 
        if(this.id=="button1"){
             b1=1;
         }else{
             b2 =1;
          }
          $("#generatePinsDialog").dialog('open');
          $.get('/MyServices/myService.svc/GeneratePINs/' + b1 +'/' + b2, function(response){

          });
      }
      $("#button1").click (OpenGeneratePINsDialog);
      $("#button2").click (OpenGeneratePINsDialog);
于 2012-11-12T14:31:55.020 回答
1

你可以做这样的事情:

$('input[type=button]').click(function(evt) {
    // setup default values for button (button2 clicked)
    var button1 = "0";
    var button2 = "1";
    // change to button 1 if that was the button pressed
    if (evt.target.id == 'button1') {
        button1 = "1";
        button2 = "0";
    }
    // execute the rest of your code
    $("#generatePinsDialog").dialog('open');
    // append the values of button1 and button2
    $.get('/MyServices/myService.svc/GeneratePINs/' + button1 + '/' + button2);
})

注意你的$.get功能不完整

于 2012-11-12T14:33:55.110 回答