Use the attr method of jQuery to modify the onclick value, jqueryattr

Source: Internet
Author: User

Use the attr method of jQuery to modify the onclick value, jqueryattr

Okay. paste the js Code directly.

Var js = "alert ('B:' + this. id); return false; "; var newclick = eval (" (function () {"+ js +"}); "); $ (" # anchor "). attr ('onclick ',''). click (newclick );

If the onclick event has a value, clear it first, and then assign a value using click (eval (function () {...}).

$ ("Input [name = 'ordercar']"). attr ('onclick ',''). click (eval (function () {Test ()}); function Test () {alert ("Test passed! "); Return ;}

If it can help you, please step on it.


Use of attr in jquery

The type attribute is read-only.
Yes $ ("input"). hide ()
Or $ ("input"). attr ("style", "display: none ");
Try it.

In IE7, jqueryattr ("onclick", "function () {}") is not supported. I hope JS can help solve this problem. Thank you!

The attr method of jQuery adds attributes to the specified object. First, there should be an object, such
: $ ("# Div"). attr (); then the onclick attribute cannot add a function, because onclick itself is an attribute of javascript, so it cannot be a function when assigned a value. You can assign a value to the function body!
$ ("# Btn"). attr ('onclick', 'alert ("dddd ")')

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.