简单的JQuery问题 - 如何为title属性添加值?

时间:2022-11-26 23:25:28

Stupid question time - how do you update the title attribute of a control? Obviously this does not work:

愚蠢的提问时间 - 如何更新控件的title属性?显然这不起作用:

$("#valPageIndex").attr('title') = pageIndex;

3 个解决方案

#1


$("#valPageIndex").attr('title', pageIndex);

Basically, $("#valPageIndex").attr('title') is just for getting its value, while $("#valPageIndex").attr('title', value) is for setting it.

基本上,$(“#valPageIndex”)。attr('title')仅用于获取其值,而$(“#valPageIndex”)。attr('title',value)用于设置它。

Here's the official doc: http://docs.jquery.com/Attributes/attr.

这是官方文档:http://docs.jquery.com/Attributes/attr。

#2


$("#valPageIndex").attr({'title': pageIndex});

#3


$("#valPageIndex").attr('title', pageIndex);

http://docs.jquery.com/Attributes/attr#keyvalue

A common jQuery convention is to have .foo() or .foo('selector') act as a getter and .foo(value) or .foo('selector', value) act as a setter.

一个常见的jQuery约定是让.foo()或.foo('selector')充当getter,而.foo(value)或.foo('selector',value)充当setter。

#1


$("#valPageIndex").attr('title', pageIndex);

Basically, $("#valPageIndex").attr('title') is just for getting its value, while $("#valPageIndex").attr('title', value) is for setting it.

基本上,$(“#valPageIndex”)。attr('title')仅用于获取其值,而$(“#valPageIndex”)。attr('title',value)用于设置它。

Here's the official doc: http://docs.jquery.com/Attributes/attr.

这是官方文档:http://docs.jquery.com/Attributes/attr。

#2


$("#valPageIndex").attr({'title': pageIndex});

#3


$("#valPageIndex").attr('title', pageIndex);

http://docs.jquery.com/Attributes/attr#keyvalue

A common jQuery convention is to have .foo() or .foo('selector') act as a getter and .foo(value) or .foo('selector', value) act as a setter.

一个常见的jQuery约定是让.foo()或.foo('selector')充当getter,而.foo(value)或.foo('selector',value)充当setter。