Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用var name&;将多个值传递/发送到jQuery函数;元素[init(div:';#div';,txt:';hello';)/init(div=';#div';,txt=';hello';)_Javascript_Jquery_Html_Css_Web - Fatal编程技术网

Javascript 使用var name&;将多个值传递/发送到jQuery函数;元素[init(div:';#div';,txt:';hello';)/init(div=';#div';,txt=';hello';)

Javascript 使用var name&;将多个值传递/发送到jQuery函数;元素[init(div:';#div';,txt:';hello';)/init(div=';#div';,txt=';hello';),javascript,jquery,html,css,web,Javascript,Jquery,Html,Css,Web,我想知道如何将值传递/发送给具有变量名和元素的jQuery函数 比如: 我可以通过init('div','hello')直接将值传递/发送到此函数,但这个过程的主要问题是我必须以相同的方式定义这些值(如函数[div-1st,txt-2nd]中定义的) 如何发送具有适当变量名的相同值。因此,如果我可以在我想要的地方定义这些值,比如init(txt:'hello')/init(div:'#div')/init(txt:'hello',div:'#div')那么使用: 示例:如何使用: 示例:perf

我想知道如何将值传递/发送给具有变量名和元素的jQuery函数

比如:

我可以通过
init('div','hello')直接将值传递/发送到此函数,但这个过程的主要问题是我必须以相同的方式定义这些值(如函数
[div-1st,txt-2nd]
中定义的)

如何发送具有适当变量名的相同值。因此,如果我可以在我想要的地方定义这些值,比如
init(txt:'hello')
/
init(div:'#div')
/
init(txt:'hello',div:'#div')
那么使用:

示例:

如何使用:


示例:

perfect answer@cherniv:)嗨,请看一下这个“”。感谢完美的回答@cherniv:)嗨,请看一下这个“”。谢谢
  $(document).ready(function(){
      init(div:'#div',txt:'hello'); //init(div='#div',txt='hello');
  });


  function init(div,txt){
    ....
  }
$(document).ready(function(){
      init( { div:'#div', txt:'hello' } );
  });


  function init( obj ){
     obj.div; //  '#div'
     obj.txt; //  'hello'
  }