选择一个xHTML标记并使用jquery将其属性存储到数组中

时间:2011-09-10 18:59:23

标签: php jquery xhtml

我如何使用jquery todo: 1-阅读特定的URL 2-将特定的xhtml标记值存储到数组中 3-将此数组传递给PHP脚本

这些是标签

<img class="nytmm_slidingMultimedia_imageSlide" style="display: inline; height: 620px; width: 930px;" src="http://graphics8.nytimes.com/images/2011/02/28/world/africa/20110301_LIBYA-slide-FBZQ/20110301_LIBYA-slide-FBZQ-jumbo.jpg">

在上面的标签中我想将一个src列表存储到一个数组中(可能有不同src的img标签)

<div class="nytmm_bigPhotoGallery_caption">Residents of Sabratha rallied in support of Colonel Qaddafi in front of a bank where they were waiting to receive a one-time 300 Dinar bonus offered to every Libyan citizen by the regime.</div>

在上面的标签中我想将div中的值或文本存储到另一个数组中 (可能有不同内容的div标签)

然后我想将这两个数组传递给php,我可以设法完成剩下的任务。

感谢和问候

1 个答案:

答案 0 :(得分:1)

var requestData = {}; // data object for future ajax request
requestData.src = []; // array for storing your src values
// getting multiple src values
$('.nytmm_slidingMultimedia_imageSlide').each(function(index){
  requestData.src.push($(this).attr('src'));
});
// getting single div text, be sure that there is only one div selected
requestData.text = $('.nytmm_bigPhotoGallery_caption').first().text();
// make an ajax request
$.post( 'some/handler.php', requestData, function(response) { console.log(response)} );

只有一些如何获得单值和乘法的例子。