Home > Web Front-end > JS Tutorial > How should jquery set the onclick event that changes the button input_Basic knowledge

How should jquery set the onclick event that changes the button input_Basic knowledge

WBOY
Release: 2016-05-16 17:46:55
Original
1284 people have browsed it

How should jquery set the onclick event of button input? For example, there is a button at the beginning: This Lines of code are generated in the background of the program, just like the approach in the Discuz!NT forum source code. Everything on the page, including scripts, are generated by the background code... and then loaded into the page using jquery.ajax... except for ie8. Except that it cannot be displayed... other browsers are normal. The problem now is: to dynamically change the onclick function of the previous page button. I have tried many methods, but none of them have worked. The following are listed below. An example of failure:
1. JavaScript code:

Copy code The code is as follows:

$(“#prebt”).unbind(“onclick”,function(){var p= $(“#nextbt”).parent();$(“#nextbt”).remove();
p .append(“”)});
JavaScript code:
$(“ #prebt”).removeAttr(“onclick”);
$(“#prebt”).attr(“onclick”,”ToPage(4)”);
or:
$(“#prebt ").attr("onclick","");
$("#prebt").attr("onclick","ToPage(4)");

2.JavaScript code:
Copy code The code is as follows:

$(“#prebt”).removeAttr( "onclick");
$("#prebt").click(function(){ToPage(4)}); //This sentence will cause an infinite loop.. I don’t know what is going on..
// The paging function I made...written like this causes the data to keep jumping around. How should I solve it?

There is really no other way but to post relevant requests online. A friend asked me if the effect I want is as follows:
Copy code The code is as follows:

$(“#prebt”).unbind(“onclick”);
$(“ #prebt”).bind(“onclick”,”ToPage(4)”);

Actually, the effect I want is the same as above, but the above method has my original effect. It's almost the same, but it can't be executed, and it can't be bound at all.
An enthusiastic netizen gave me a code example, which he said was helpful to me. The details are as follows:
XML/HTML code:
Copy code The code is as follows:

.org/1999/xhtml">


< title>Untitled Document








The above is tested in ie8 When clicked, the result is 1. Even so, it is not the effect I originally wanted. Is there really no way to achieve it?
In the end, I came up with a relatively stupid method, which can be implemented as follows:

Copy code Code As follows:


Then the background program automatically replaces the content in prespan.

Copy code The code is as follows:
$('#prespan').empty();
$('#prespan').append("
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template