我有一些PHP代碼:打開多個鏈接與點擊
foreach($moduid as $k=>$mod) {
$random = $k+1;
echo '<a href="http://mysite.com?y='.$cid.'&t='.$mod.'&s=-2" data-pack="true" id="link'.$random.'">data</a>';
}
和JS代碼:
$(document).ready(function() {
var $hash = new Array(); // We create new Array
$('a').click(function(){ // On each click to <a> 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 :)
});
});
我已經使用了一些這樣的:Open Links in Multiple Browser Windows/Tabs
然而,似乎沒有工作,當我點擊提交。我不太瞭解JS,並希望有人知道爲什麼按提交不會在新標籤中打開所有這些鏈接。我正在使用這個jQuery - http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
它在IE8中工作,但不是Firefox和Chrome,我希望它打開所有鏈接,不僅僅是我選擇的鏈接。所以也許這不是正確的工作JS?
在Firefox中,它只是在鏈接之後。
謝謝
它不。此代碼適用於Opera和IE8一次性使用。我在FF和Chrome上嘗試了很多東西,但沒有運氣。我編輯了一下:http://pastebin.com/1HsBuix9,它不工作。我不希望用戶詢問他們是否想要這個和那個鏈接,他們只需按下提交併打開所有。 – Dean 2011-02-17 06:16:37
我說的並非如此之多,而是與瀏覽器製造商和最終用戶的哲學背道而馳。您如何確保最終用戶實際上想要打開多個鏈接?當你可以回答這個問題時,你回答自己的問題。 – Lance 2011-02-17 06:28:49