Home  >  Article  >  Backend Development  >  javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?

javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?

WBOY
WBOYOriginal
2016-06-06 20:14:091610browse

<code><img  src="mainPic.jpg" alt="javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?" >
<volist name="dataSet" id="vi">
    <img  src="%7B%24vi.url%7D.jpg" alt="javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?" >
</volist></code>

要如何实现 在鼠标移动到volist遍历输出dataSet图片上时,volist上方的mainPic替换为鼠标移动过的图片?
我用Js获取到的volist中的图片始终是dataSet中的第一张图片的src。

回复内容:

<code><img  src="mainPic.jpg" alt="javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?" >
<volist name="dataSet" id="vi">
    <img  src="%7B%24vi.url%7D.jpg" alt="javascript - thinkphp下,在js如何获取模板遍历输出的结果中的某一条?" >
</volist></code>

要如何实现 在鼠标移动到volist遍历输出dataSet图片上时,volist上方的mainPic替换为鼠标移动过的图片?
我用Js获取到的volist中的图片始终是dataSet中的第一张图片的src。

新建一个数组,循环将你的dataSet集合的元素push到这个数组中,然后从这个数组中获得你想要的任何一个元素。
话不多说,直接上代码

<code>var arr = [];
<volist name="dataSet" id="vi">
    arr.push({"key1":"{$vi.key1}","key2":"{$vi.key2}",...});
</volist>

//arr就是一个js数组,随便你怎么用</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn