在 jquery 中为变量赋值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15394461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 14:57:11  来源:igfitidea点击:

Assign value to a variable in jquery

jqueryvariablesdrop-down-menuvariable-assignment

提问by Manny Balboa

How do i assign a value to a variable in Jquery

我如何在 Jquery 中为变量赋值

    {var c2;
    $(c2).val("standard_desc");
    alert (c2);
    $('#ANDCriteria2').val(c2); 

    } 

I am trying to set variable's value, it will be static. In next line i am trying to set dropdown's selected value using same variable. I know i can just type

我正在尝试设置变量的值,它将是静态的。在下一行中,我尝试使用相同的变量设置下拉列表的选定值。我知道我可以打字

$('#ANDCriteria2').val("standard_desc");

But i have different requirement, please guide.

但我有不同的要求,请指导。

回答by Apollo SOFTWARE

just declare the variable in JavaScript.

只需在 JavaScript 中声明变量。

 <script>
   var c2;
   c2 = "value";
 </script> 

回答by bipen

i have no idea why you have {there in your question.. are you missing something.. anyways assigning value to a variable is super simple.. use =operator

我不知道你为什么{在你的问题中出现......你是否遗漏了什么......无论如何为变量赋值非常简单......使用 =运算符

var c2 = "standard_desc";
 alert(c2);
 $('#ANDCriteria2').val(c2);

回答by user3776645

Try this way..

试试这个方法。。

<script src="//code.jquery.com/jquery-1.10.2.js"></script>

<input id="points" type="text" value="">
<input id="var" type="text" value="">

$( "input" )
  .keyup(function() {
    var points= $("#points" ).val();
    $( "#var" ).val( (points));
  })
  .keyup();

回答by thitemple

It is just JavaScript:

它只是 JavaScript:

var c2 = "value";

回答by Biswajit

<script>
function fun()
{
var c2="standard_desc";
    alert (c2);
    $('#ANDCriteria2').val(c2); 

    } 
</script>