在JQuery / JQuery Mobile中获取div元素的内容 [英] Get content of div elements in JQuery/JQuery Mobile
问题描述
我正在创建一个移动网络应用。
我有3个.html文件。 1:products1.html 2:products2.html 3:allproducts.html
在products1.html和products2.html上,我有div元素显示我的产品,例如来自product1.html:
Im creating a mobile web app.
I have 3 .html documents. 1: products1.html 2: products2.html 3: allproducts.html
On products1.html and products2.html, I have div elements showing my products, example from product1.html:
<div data-role="content" id="product1items">
<ul data-role="listview">
<li>
<a href="item1.html" data-ajax="false" data-transition="slide">
<img src="images/item1.jpg">
<h2>Item1</h2>
</a>
</li>
</ul>
</div>
在allproducts.html上我想从products1.html获取/获取元素products2.html,所以这个页面将显示我的所有产品。我将如何在JQuery / JQuery Mobile中执行此操作?
请记住我(几乎)一个初学者
On allproducts.html I would like to get/fetch the elements from products1.html and products2.html, so this page will showing all my products. How would I do this in JQuery/JQuery Mobile ?
Please bear in mind Im (almost) a total beginner
推荐答案
在jQuery中有选择器概念与css相同,我们用来从HTML DOM中选择任何元素。
喜欢选择一个div的id是: -
In jQuery there is selector concept same as in css we used to select any element from HTML DOM.
Like to select a div by its id is :-
( #divTest)。html();
("#divTest").html();
在您的方案中,您有
- product1.html和product2.html中的元素你可以简单地给它们两个ID,例如
在products1.html
Here in your scenario you have
- element in both product1.html and product2.html you can simply give a id to both of them like
In products1.html
<ul id="ulPoducts1"></ul>
同样
in products1.html
similarly
in products1.html
<ul id="ulPoducts1"></ul>
现在获取ul元素的内部html并将它们放入在以下两个变量中: -
Now get the inner html of both the ul element and put them in two variables like below :-
var products1 =
( #ulProducts1)。html(); // 包含所有产品< ul>< li>来自products1.html页面的元素
var products2 =
("#ulProducts1").html(); // contains all products as <ul><li> elements from products1.html page var products2 =
这篇关于在JQuery / JQuery Mobile中获取div元素的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!