How to pass a parameters to this jquery?
i dont have a clue how i should rewrite this jquery so i can pass parameters into it. i want to pass an id into the function so i place it like, $(".dialog" + id)
.
i am goin to trig开发者_运维知识库ger it with a <a>
$(document).ready(function() {
$(".btnCheck").live("click", function(evt) {
evt.preventDefault();
$(".dialog").dialog({
height: 700,
width: 600,
closeOnEscape: true,
title: 'prev'
}).dialog("open");
});
});
Assuming:
<input type="button" class="btnCheck" id="btn1" value="Click Me">
...
<div id="dialog-btn1" class="dialog">
...
</div>
you can do:
$(function() {
$(":button.btnCheck").live("click", function(e) {
$("#dialog-" + this.id).dialog({...});
e.preventDefault();
});
});
You'll note that instead of using a dynamic class name, I gave the div a class of dialog. To get a specific one, since you will only ever want one (at a time), an ID is a better choice (imho).
this
within this event handler refers to the button that was clicked ie the source of the event.
assuming that what you want is the ID of "btnCheck.
$(document).ready(function() {
$(".btnCheck").live("click", function(evt) {
evt.preventDefault();
$(".dialog" + $(this).attr("id")).dialog({ height: 700, width: 600, closeOnEscape: true, title: 'prev' }).dialog("open");
});
});
You need to associate your buttons with you dialogs somehow.
If you give the buttons a class of button and the dialogs a class dialog. You can then get all this into an array and loop through them the first button in the array will activate the dialog which has an id of dialog1.
精彩评论