只需单击一下即可在新选项卡中打开多个链接
我有一些PHP代码:
foreach($moduid as $k=>$mod) { $random = $k+1; echo 'data'; }
和JS代码:
$(document).ready(function() { var $hash = new Array(); // We create new Array $('a').click( function(){ // On each click to element if ( $(this).attr("data-pack") == "true" ) { // check wether this is one of the links we use $hash[$(this).attr("id")] = $(this).attr("href"); // We add href value into $hash object $(this).css("color","green"); // Way to mark selected ones $(this).attr("data-pack", "selected"); // Change data-pack property value to selected return false; // We don't want to execute this yet } else if ( $(this).attr("data-pack") == "selected" ) { // In case you change your mind and want to unselect $(this).attr("data-pack", "true"); // Change data-pack property back, thanks to Ambrosia pointing it out in the comment $(this).css("color","red"); // We mark it as unset delete $hash[$(this).attr("id")]; // Remove it from hash return false; } }); $("form").submit( function(){ // After we submit for (var i in $hash) { // Go trough $hash window.open($hash[i]); // And open window for each member } return false; // We don't actually want to submit form, just open new windows :) } ); });
我已经使用了一些: 在多个浏览器Windows / Tabs中打开链接
但是,当我点击提交时,它似乎不起作用。 我真的不了解JS,并希望有人知道为什么按提交不会在新标签中打开所有这些链接。 我正在使用这个jQuery – http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
它在IE8中工作但不是Firefox或Chrome,我希望它打开所有链接而不仅仅是我选择的链接。 那么也许这不是正确的JS工作?
在Firefox中,它只是跟随链接。
谢谢
去解锁弹出窗口,你的代码应该工作。
HTML:
$mod) { $random = $k+1; echo 'data'; } ?>
JS:
$("form").submit(function(){ alert('asdf'); $('a').each(function(){ $(this).attr('target','_blank'); window.open($(this).attr('href')); }) return false; } );
为我工作。