-1

html 看起来像这样:

<ul class="categoryitems">
    <li><a data-url="../po/browse_po.php" href="welcome.php" target="main">PURCHASE ORDERS</a></li>           
    <li><a data-url="../po/po_email_config.php" href="welcome.php" target="main">PO EMAILS</a></li>     
</ul>

忽略它们不相关的href。我计划防止他们违约。

相关的是jquery失败:

$('a').click(function()
    {
        alert($(this).parent().html()); //shows the a tag with the data-url attribute
        //$(this).data('url',"..someurl.com");
        alert($(this).data('url')); //returns undefined; when the previous line is uncommented works 
        alert($(this).attr('data-url')); //this works        
    });

如果它有所不同,则单击功能将包含在以下内容中:

$("#wndNavbar").ready( function() { 

});

因为它在一个框架中:

<frameset cols="<?=$gl_navbar_width?>,*" frameborder="0" framespacing="5" border="0">
    <frame id="wndNavbar" name="wndNavbar" src="nav_bar.php" scrolling="auto" marginheight="0" noresize>
    <frame name="main" src="welcome.php" scrolling="auto" marginheight="0" noresize>
</frameset>  
4

1 回答 1

2

这不是你阅读的方式data-url。这是正确的方法:

alert($(this).data('url'));

或者

alert($(this).attr('data-url'));

更新:由于上述内容似乎无法为您解决问题,您是否尝试过使用

$(document).ready(function() {

});

或者

$("#wndNavbar").live(function() {

});

代替

$("#wndNavbar").ready( function() { 

});

更新 2:您似乎使用的是frame,而不是iframe. ready不适用于frames,因此您需要使用load

$("#wndNavbar").load( function() { 

});
于 2013-03-22T23:18:41.390 回答