开发者

how do i retrieve a textbox's title and name using jquery?

开发者 https://www.devze.com 2022-12-28 17:18 出处:网络
how do i retrieve a 开发者_JS百科textbox\'s title and name using jquery?$(\'#textbox\').attr(\'title\')

how do i retrieve a 开发者_JS百科textbox's title and name using jquery?


$('#textbox').attr('title')
$('#textbox').attr('name')


Textbox, like an input element? Depending on where it is in the document, your selector may vary, but I'll assume you've given it an id, so the HTML would look something like this:

<input type="text" title="tehTitle" name="tehName" id="textBox" />

Since jQuery selectors use CSS syntax we can target by id attribute:

$("input#textBox") // more to come...

You can then use the jQuery attr function to read it's title and name attribute.

var title = $("input#textBox").attr("title");
var name = $("input#textBox").attr("name");


var attributeText = $("#textboxID").attr("attributeYouWantToRetrieve");

just replace title and name for attributeYouWantToRetrieve


var theTextBox = $('textarea');
var itsTitle = theTextBox.attr('title');
var itsName = theTextBox.attr('name');

Maybe you should do some more tutorials :|

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号