function A(a, b, c, d) {
 var html = '<form method="POST" name="simple">'
    + '      <input type="button" onClick="B(a,b,c,d)">'
    + '  </td></tr>'
+ '  </table> '      
+ '</form>';
  return html;
}请问如何将A()中的参数传递到B()中?求指教,谢谢。js 传值

解决方案 »

  1.   


    '      <input type="button" onClick="B(\''+ a +'\',\''+ b +'\',\''+ c +'\',\''+ c +'\')">'
      

  2.   

    function A(a, b, c, d) {
      var html = '<form method="POST" name="simple">'
               + '<input type="button" onClick="B('+arguments+')">'
               + '</td></tr>'
               + '</table> '
               + '</form>';
      return html;
    }
      

  3.   


    你传给A的typeof(a)是什么类型到B中就是什么类型
      

  4.   


    你传给A的typeof(a)是什么类型到B中就是什么类型我知道如果直接在js中调用方法,传递过去的参数是没问题的。请问在这种html中应该怎么写???
      

  5.   


    你传给A的typeof(a)是什么类型到B中就是什么类型我知道如果直接在js中调用方法,传递过去的参数是没问题的。请问在这种html中应该怎么写???
    A返回的就是一个字符串,除非你返回的是一个对象
      

  6.   

    如果你一定要这么写的话,只能把 
    a, b, c, d 存到时全局里先, 当执行B时去取
      

  7.   

     <div id="main"></div>
    <button onclick="add()" >add</button>
    <script language=javascript>
    var args=[],nn=0;
    function A(a, b, c, d) {
      var html = '<form method="POST" name="simple">'
               + '<input type="button" value="bnt" onClick="B('+ nn++ +')">'
               + '</td></tr>'
               + '</table> '
               + '</form>';
      args.push([a,b,c,d]);
      return html;
    }
    function B(i){
    alert( args[i][0].v +','+ args[i][1]  ) //取a 对象属性v ,b
     
    }
    function Obj(v){this.v=v}
    function add(){
    var main=document.getElementById('main');
    main.insertAdjacentHTML("BeforeEnd", A(new Obj(nn),2,3,4));
      }
    </script>
      

  8.   


    不好意思再问下,我要在B()函数里传递四个参数,在页面上点击“btn”按钮时就直接将参数传递过去了,不会再调用其他的js函数,请问这种情况下应该如何传值。
      

  9.   


    不好意思再问下,我要在B()函数里传递四个参数,在页面上点击“btn”按钮时就直接将参数传递过去了,不会再调用其他的js函数,请问这种情况下应该如何传值。
    你要直接传只能是 按#1楼那样改了
      

  10.   

    这种形式只能传递字符串,如果参数是对象的话,可以在调用A函数时传递json字符串,就行了比如A("{\"a\":1}",1,1,1);则B函数接收到的参数a就是一个对象,
    不过不建议这么做,麻烦且不太合理,还是换另外的方式合适
      

  11.   


    function A(a, b, c, d) {
     var html = '<form method="POST" name="simple">'
        + '      <input type="button" onClick="B(\'' + {\"a\":1} + '\',\'' + {\"b\":1} + '\',\'' + {\"c\":1} + '\',\'' + {\"d\":1} + '\')">' //这样写直接报错,请问格式应该是什么,谢谢。
        + '  </td></tr>'
    + '  </table> '      
    + '</form>';
       return html;
    }
      

  12.   


    function A(a, b, c, d) {
     var html = '<form method="POST" name="simple">'
        + '      <input type="button" onClick="B(\'' + {\"a\":1} + '\',\'' + {\"b\":1} + '\',\'' + {\"c\":1} + '\',\'' + {\"d\":1} + '\')">' //这样写直接报错,请问格式应该是什么,谢谢。
        + '  </td></tr>'
    + '  </table> '      
    + '</form>';
       return html;
    }
    你都不按照字符串格式乱来,当然是错的
     + '<input type="button" onClick="B({\"a\":1},{\"b\":1},{\"c\":1},{\"d\":1})"....
      

  13.   

    你都不按照字符串格式乱来,当然是错的
     + '<input type="button" onClick="B({\'a\':1},{\'b\':2},{\'c\':3},{\'d\':4})"....谢谢。通过这种方式abcd可以作为一个object类型传递过去,可是为什么A(a,b,c,d)传进来的对象的各种属性没有传到B(a,b,c,d)里面去?
      

  14.   


    function A(a, b, c, d) {
     var html = '<form method="POST" name="simple">'
        + '      <input type="button" onClick="B(\'' + {\"a\":1} + '\',\'' + {\"b\":1} + '\',\'' + {\"c\":1} + '\',\'' + {\"d\":1} + '\')">' //这样写直接报错,请问格式应该是什么,谢谢。
        + '  </td></tr>'
    + '  </table> '      
    + '</form>';
       return html;
    }
    你都不按照字符串格式乱来,当然是错的
     + '<input type="button" onClick="B({\"a\":1},{\"b\":2},{\"c\":3},{\"d\":4})"....谢谢。通过这种方式abcd可以作为一个object类型传递过去,可是为什么A(a,b,c,d)传进来的对象的各种属性没有传到B(a,b,c,d)里面去?
      

  15.   


    function A(a, b, c, d) {
     var html = '<form method="POST" name="simple">'
        + '      <input type="button" onClick="B(\'' + {\"a\":1} + '\',\'' + {\"b\":1} + '\',\'' + {\"c\":1} + '\',\'' + {\"d\":1} + '\')">' //这样写直接报错,请问格式应该是什么,谢谢。
        + '  </td></tr>'
    + '  </table> '      
    + '</form>';
       return html;
    }
    你都不按照字符串格式乱来,当然是错的
     + '<input type="button" onClick="B({\"a\":1},{\"b\":2},{\"c\":3},{\"d\":4})"....谢谢。通过这种方式abcd可以作为一个object类型传递过去,可是为什么A(a,b,c,d)传进来的对象的各种属性没有传到B(a,b,c,d)里面去?
    无语了,搞半天你根本没明白怎么回事啊,我还是直接给你写吧.....
    '      <input type="button" onClick="B('+ a +','+ b +','+ c +','+ d +')">' 调用时:
    A("{\"a\":\"a\"}","{\"b\":\"b\"}","{\"c\":\"c\"}","{\"d\":\"d\"}");
      

  16.   

    换种思路径吧,这看着就蛋疼 
    不知你要传的对象有没有 Function, DOM 类型什么的,如果有你怎么转 字符串
      

  17.   


    调用A()函数是在extjs里:
    function affix_videoChanne(a, b, c, d) {
        try {
            new Ext.Window({
                layout: 'fit',
                height: 500,
                width: 850,
                collapsible: true,
                closeAction: 'hide',
                closable: true,
                plain: true,
                modal: 'true',
                title: 'PHOTO',
                items: [{
                    xtype: 'panel',
                    border: false,
                    layout: {
                        type: 'vbox',
                        align: 'stretch'
                    },
                    items: [
    {
        html: A(a, b, c, d),
        //html: A({\'a\':\'a\'},{\'b\':\'b\'},{\'c\':\'c\'},{\'d\':\'d\'}),
        //html: A({a:a}, {b:b}, {c:c}, {d:d}),
        height: 470,
        margin: '0 0 5 0'
    }
    ]
                }]
            }).show();
        } catch (e) {
            Ext.MessageBox.alert("提示", "功能异常!")
        } 

    然后在A()中
    function A(a, b, c, d) {
     var html = '<form method="POST" name="simple">'
        + '      <input type="button" onClick="B({\'a\':\'a\'},{\'b\':\'b\'},{\'c\':\'c\'},{\'d\':\'d\'})">'
        + '  </td></tr>'
    + '  </table> '      
    + '</form>';
       return html;
    }
    这种情况下没有显示的调用A()函数,请问这种情况下应该怎么处理?
      

  18.   

    A(a, b, c, d)
    这个不是调用A函数是什么?
    写成
    html:A("{\"a\":\"a\"}","{\"b\":\"b\"}","{\"c\":\"c\"}","{\"d\":\"d\"}")
    就行了,js基础需加强
      

  19.   


    为什么传递过去的只是一个空的object对象,参数里的相应的属性值没有传过去?
      

  20.   


    为什么传递过去的只是一个空的object对象,参数里的相应的属性值没有传过去?
    这个你得自己调,在函数return前把html字符串打印出来看看,有什么问题一下就清楚了
      

  21.   


    var ajson = Ext.encode(a);
    ajson =ajson.replace(new RegExp(/(")/g),'\'');通过这种方式可以将参数转变为对象,为什么我的js编译不通过???