The jQuery attr method modifies the onclick value and jquery modifies the attr value.

Source: Internet
Author: User

The jQuery attr method modifies the onclick value and jquery modifies the attr value.
The jQuery attr method modifies the onclick value.

The onclick value is modified through the attr of jQuery.

Code:

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 ()}); // www. jbxue. comfunction Test () {alert ("Test passed! "); Return ;}

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 ")')
The type attribute of attr in jquery is read-only.
Yes $ ("input"). hide ()
Or $ ("input"). attr ("style", "display: none ");
Try it.

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.