ورود

View Full Version : دسترسی به اطلاعات یک DIV به شکل منطقی تر



id1385
دوشنبه 29 خرداد 1391, 20:48 عصر
سلام
لطفاً راهنمایی کنین که چطور می تونم اطلاعات یک دیو را بخونم
نکته: دیوی که میخوام اطلاعات داخل اونو بخونم توی یک فایل جدا هست میخوام لود کنم بعد اونو بخونم خودم به شکل زیر نوشتم ولی بار اول کار نمی کنه و سری بعد کار می کنه

نکته 1 : آیا روش منطقی تری جود داره که فایل اکسترنال رو داخل صفحه لود نکنی و از همون جایی که هست بخونی؟

کد و عکسها رو ببینین ممنون


فایل html:

<div id="page1">i am page 1</div>

<div id="page2">and me, page 2</div>

<p>another thing, i didnt need, only can select above div's text</p>

<p class="test">yeah u'll can :-D</p>




فایل jquery :


$(document).ready(function(){
$("#button").click(function(){
$("#Loading").show('slow');
$('#result').load('http://127.0.0.1/sample.html',showdata());
}); //end of listening

function showdata()
{
$("#Loading").fadeOut(1200);
$("#result").show('slow',getdata());
}//function show data

function getdata()
{
$("#one").html('<b><i>Page 1: </b></i>'+$("#page1").text());
$("#tow").html('<b><i>Page 2: </b></i>'+$("#page2").text());
}//function get data

});// document end

blackmak
سه شنبه 30 خرداد 1391, 18:45 عصر
این خط را :

$("#button").click(function(){

به این خط تغییر دهید

$("#button").live('click',function(){

Cyletech
پنج شنبه 01 تیر 1391, 19:20 عصر
متد live تو جی کوئری بالای 1.7 دیگه توصیه نمیشه. از on() استفاده کنید.

As of jQuery 1.7, the .live() method is deprecated. Use .on() (http://api.jquery.com/on/) to attach event handlers.
http://api.jquery.com/live/