如何为jquery分配变量值? [英] How to assign variable value to jquery?
本文介绍了如何为jquery分配变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var s="attr" var i=$(s)
// jQuery(elem).attr(attr,eval("elm"+attr));
jQuery(elem).$(s)(attr,eval("elm"+attr));//i tried this.
如何在上面的代码中指定变量名的值(代替s)。即: - 而不是添加attr(请参阅注释行以供参考),我需要从变量中获取值。
how to assign a value of variable name in the above code(in place of s).Ie:-instead of adding attr(see the commented line for reference), i need to fetch the value from a variable.
推荐答案
不确定你在这里尝试做什么,但jQuery中的 .val()
函数可能对你有帮助。这对< form>
元素特别有用。如果您使用参数调用 val()
,它将更改元素的值:
Not sure what you're trying to do here, but the .val()
function in jQuery will probably help you. This is especially useful for <form>
elements. If you call val()
with a parameter, it will change the value of the element:
$("yourElement").val("15");
如果你打电话给 val()
而没有任何输入,它将返回元素的当前值:
If you call val()
without any inputs, it will return the current value of the element:
a = $("yourElement").val();
这篇关于如何为jquery分配变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文