开发者

jquery elementby class and set name

开发者 https://www.devze.com 2022-12-29 13:42 出处:网络
can some one help me wi开发者_如何学运维th code to get element by classname and also change the name

can some one help me wi开发者_如何学运维th code to get element by classname and also change the name

currently ive tried

$('selected').attr("name", 'blah blah');

and also

$('.selected').attr("name", 'blah blah');

noneof these work thanks


  • $('.classname') should work for finding your elements by class name (try by checking .length)
  • .attr("name", "foo") should definitely work.

Care to share some HTML code and matching JavaScript?

EDIT:

Given your sample code, and assuming you're using ASP.NET MVC's Html helper.

  1. You may be passing a bad name to HtmlHelper.DropDownList, there's a period in it ("cat.parent_id")
  2. I'm not sure HtmlHelper.DropDownList supports the way you're trying to pass a class to each <option> element (but you can verify by viewing the page's source).

If what you're trying to do is change the text in the currently-selected option, and given:

<%= Html.DropDownList('my_ddlist', someEnumerable); %>

You can try to use jQuery's ":selected" pseudo-selector instead, and change the option text with .text():

$('select#my_ddlist option:selected').text("foo");

If you're trying to do something else, can you explain what?

0

精彩评论

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

关注公众号