how to define variable in jquery

2020-05-15 14:54发布

I would like to know how to declare a variable in jQuery

The code I am currently using is

$.name = 'anirudha';
alert($.name);

That code works fine, but if I write it as

$.name = document.myForm.txtname.value;
alert($.name);

Then my code does not work.

8条回答
家丑人穷心不美
2楼-- · 2020-05-15 15:34
var name = 'john';
document.write(name);

it will write the variable you have declared upper

查看更多
等我变得足够好
3楼-- · 2020-05-15 15:36

In jquery, u can delcare variable two styles.

One is,

$.name = 'anirudha';
alert($.name);

Second is,

var hText = $("#head1").text();

Second is used when you read data from textbox, label, etc.

查看更多
登录 后发表回答