在javascript / jquery中显示数据的最佳方式 [英] Best way to display data in javascript/jquery

查看:45
本文介绍了在javascript / jquery中显示数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var resultArr = ["A","B","C"];

    var arrayLength = resultArr.length;
    for (var i = 0; i < arrayLength; i++) {

        res = res + resultArr[i].label + "<br /> ";



       $("#result").html(res);



    }


}







<a id="result"></a> 





我的数据如果我的例子有3个项目3项目显示在与链接相同的行中,但我想分割每个项目并显示1个链接到每个项目而不是全部相同?





我想点击显示的标题转到该URL。

现在,如果我在输入框中键入Sub,我的for循环中的计数将获得3个项目并显示它们像这样,但我的标题现在超链接它只有1个超链接的所有标题

所以徘徊在标题上,它的下划线就像所有的标题都在同一个href,

但是我想要像这样显示它们



ASub1

Sub1

Sub2





ASub1(本页链接) )

Sub1(此页面的链接)

Sub2(此页面的链接)



现在它显示



ASub1(此页面的链接

Sub1

Sub2)



My data if i example have 3 items the 3 items are displayed in same line as a link but i want to split every item and display 1 a link to every item and not all the same on line?


I want to clicken the title that are displayed go to that URL.
Right now if i in my input box type Sub the count in my for loop gets 3 items and displays them like this but my titles are now hyper links its just 1 hyperlink all over the titles
so when hover over the titles its gets underline like all the titles are in a same a href,
but i want to display them like this

ASub1
Sub1
Sub2


ASub1 (link for this page)
Sub1 (link for this page)
Sub2 (link for this page)

Right now it displays

ASub1 (link for this page
Sub1
Sub2 )

推荐答案

#results)。html(res);



}


}
("#result").html(res); } }







<a id="result"></a> 





我的数据如果我的例子有3个项目3项目显示在与链接相同的行中,但我想分割每个项目并显示1个链接到每个项目而不是全部相同?





我想点击显示的标题转到该URL。

现在,如果我在输入框中键入Sub,我的for循环中的计数将获得3个项目并显示它们像这样,但我的标题现在超链接它只有1个超链接的所有标题

所以徘徊在标题上,它的下划线就像所有的标题都在同一个href,

但是我想要像这样显示它们



ASub1

Sub1

Sub2





ASub1(本页链接) )

Sub1(此页面的链接)

Sub2(此页面的链接)



现在它显示



ASub1(此页面的链接

Sub1

Sub2)



My data if i example have 3 items the 3 items are displayed in same line as a link but i want to split every item and display 1 a link to every item and not all the same on line?


I want to clicken the title that are displayed go to that URL.
Right now if i in my input box type Sub the count in my for loop gets 3 items and displays them like this but my titles are now hyper links its just 1 hyperlink all over the titles
so when hover over the titles its gets underline like all the titles are in a same a href,
but i want to display them like this

ASub1
Sub1
Sub2


ASub1 (link for this page)
Sub1 (link for this page)
Sub2 (link for this page)

Right now it displays

ASub1 (link for this page
Sub1
Sub2 )


您好,



您的代码有一些小变化。在for循环中,您使用的是div元素的text属性,每次只从数组中获取最后一项。在for循环的每个计数中,div文本都被覆盖,这就是为什么只有数组显示的最后一项。你应该使用append而不是那个文本。



我对你的代码做了一些修改:



Hi,

There is small change in your code. In for loop, you are using text property of div element, which takes only last item from array every time. In every count of for loop, div text is override that's why only last item from array display. You should use append rather that text.

I made some changes in your code :

function successHandler(data) {

        var jsonObject = JSON.parse(data.body);
        var dataArr =


.makeArray(jsonObject.d.results);
var resultArr =
.makeArray(jsonObject.d.results); var resultArr =


这篇关于在javascript / jquery中显示数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆