What can I use to show/hide a clickable button?
I'd like to use a "hidden" div that will contain a click-able image link based on a PHP return value.
Can someone please point me to an example? I know there is a 开发者_开发知识库name for this but I don't know what it's called.
Show: (api url)
$("#mybuttondivID").show();
Hide: (api url)
$("#mybuttondivID").hide();
An example:
<html>
<head>
<title> Show/Hide example</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="mybuttondiv">
<a href="http://www.google.com"><img src="http://www.google.be/intl/en_com/images/srpr/logo1w.png" alt="Google" /></a>
</div>
<script type="text/javascript">
$(document).ready(function () {
// hide the buttondiv before we do the ajax call
$("#mybuttondiv").hide();
//do an ajax request to a php page
$.ajax({
type: "GET",
url: "fetch_data.php",
success: function (html) {
//do something when the response returns
// in this case, we make the button visible again
$("#mybuttondiv").show();
},
error: function (request) {
//ajax failed, display button again
$("#mybuttondiv").show();
}
});
});
</script>
</body>
</html>
And here is a link to the jquery $.Ajax
help page:
http://api.jquery.com/jQuery.ajax/
Maybe you're looking for a combination of .hide()
, .show()
, .toggle()
and/or $.get()
?
EDIT: Based on your comment above, maybe this is what you're after:
var hidden = $('#someDiv, #someLink').hide();
$.get('someScript.php', function() {
hidden.show();
});
精彩评论