I wonder if anyone can help with a jQuery problem I am having.
I am using the tooltips from the Jquery Tools library to create a popup window when mousing over an hrefed image, this I want to use to cusomise the call to change the content in the DIV.
The links I am using are in the form:
<a href="/venue/1313.htm" class="quickView"><img src="/images/site/quickView83.png" alt="Quick View" width="83" height="20" /></a>
The code I am using to trigger the tip is:
$(".quickView").live('mouseover', function()
{
if (!$(this).data('init'))
{
$(this).data('init', true);
ajax_quickView();
$(this).tooltip
({
/* tooltip configuration goes here */
tip: "#quickViewWindow",
position: "right",
offset: [0, -300],
effect: 'slide'
});
$(this).trigger('mouseover');
}
});
I have tried th开发者_如何学Pythone following function to grab the ID (in the example above, 1313) from the link:
function ajax_quickView(){
var pageNum = $("a.quickView").attr("href").match(/venue/([0-9]+)/).htm[1];
$("#quickViewWindow").load("/quick-view/", function(){})
}
However I think this is where it falls down, I think my regex is prob to blame...
Once I get the var pageNum I presume I can just pass it into the .load as:
$("#quickViewWindow").load("/quick-view/", {id : pageNum }, function(){})
Many thanks
Firstly, you haven't correctly escaped the /
character in your regex:
/venue/([0-9]+)/
// should be
/venue\/([0-9]+)/
Secondly, you haven't correctly ended your regex, the entire line has a few syntax errors:
.match(/venue/([0-9]+)/).htm[1];
// should be
.match(/venue\/([0-9]+).htm/)[1];
I don't know the tooltip plugin but I think your approach is a little bit... cumbersome. I worked with the jQuery tools and their overlay and it allowed to register a callback that would be handed the event source, in this case that would be the hrefd image which you can just ask for the actual URL. Might not be the answer you are looking for, but I just feel that you are making this more complicated than necessary.
精彩评论